【发布时间】:2021-01-31 01:40:33
【问题描述】:
基本上我和 Github 上的 this 和 this 问题有相同的问题,不幸的是,这两个问题在回答之前都已关闭:/
我正在使用带有 Typscript 和 Vue 类组件的 Vue。
我需要做的是从@Component 装饰器内的观察者内部访问我的(Vue-)类的方法。
我知道使用this.$data 可以访问组件的数据,但是方法呢?
我的代码在运行时工作,但在 vscode 中产生编译时错误和错误(“属性 'clearInfo' 不存在于类型 'Vue'。”);
@Component({
watch: {
firstMesh(newMesh) {
if (newMesh === undefined) this.clearInfo(1); // this produces the errors
else this.showMeshInfo(newMesh, 1);
},
secondMesh(newMesh) {
if (newMesh === undefined) this.clearInfo(2);
else this.showMeshInfo(newMesh, 2);
},
},
})
export default class Info extends Vue {
clearInfo(whichMesh : number) {
...
}
showMeshInfo(mesh : any, index : number) {
....
}
}
【问题讨论】:
标签: javascript typescript vue.js vue-class-components