I very recently started playing around with TypeScript on my Vue.js projects. For my current project (a very simple chat application) I have created a TypeScript class called ChatParent.ts. It contains all methods and variables necessary for sending/receiving messages. I extend this class in my other components. Calling the parent methods from these child class works fine, however, when I monitor a variable in the parent class (e.g., username) the change is not reflected in the DOM of the child component.
I have tried adding setter/getter methods and computed properties (e.g., get methodName(): boolean), neither of which works.
The code below is from ChatParent.ts and has been simplified.
@Component({
name: "ChatParent",
})
export default class ChatParent extends Vue {
private chatClient: new ChatClient(...);
subscribed: boolean = false;
username: string = "";
subscribe() {
const subscriptionRequest = new SubscriptionRequest();
subscriptionRequest.setUsername(username);
this.chatClient.subscribe(subscriptionRequest).on("data", data => {
this.subscribed = true;
});
}
...
}
The following is from TypeBox.vue.
<template>
<v-container pa-2>
<v-textarea
outline
label="Type message here..."
:disabled="!subscribed"
v-model="message"
></v-textarea>
</v-container>
</template>
<script lang="ts">
import {Component} from "vue-property-decorator";
import ChatParent from "@/components/ChatParent.ts";
@Component({
name: "TypeBox",
})
export default class TypeBox extends ChatParent {
message : string = "";
}
</script>
Whenever the data callback is called in the subscribe(...) method, the subscription variable gets updated in the parent class, but the change is not reflected in the child component (where it is supposed to enable the text area if the subscribe variable is true).
I think that my understanding of Vue + TypeScript is perhaps completely incorrect (with regards to extending classes). I would, therefore, really appreciate some insight.