我正在使用 Vue 2/typescript 和 vue-property-decorator 编写应用程序。在我的组件中,我使用 beforeRouteEnter/beforeRouteUpdate 挂钩。我的组件有方法 findProjects,我想在我的beforeRouteUpdate挂钩中调用这个方法。
我的组件:
import { Component, Vue, Mixins, Watch } from 'vue-property-decorator'
...
export default class ProjectSandboxTs extends Mixins(GlobalFilterMixin({})) {
created() {...
}
clearInput() {...
}
findProjects() {
const filter: IFilter = { ...this.modalFilterValues, ...this.filterValues }
this.filterProjects(filter)
this.displayProjects()
this.isEmpty = this.filteredData.length === 0
}
filterProjects(filter: IFilter) {...
}
但是当我尝试在我的钩子中调用组件的方法时,我得到了打字稿错误:“Vue”类型上不存在属性“findProjects”
beforeRouteUpdate(to, from, next) {
if (!isEqual(to.query, from.query)) {
this.findProjects() // <== Property 'findProjects' does not exist on type 'Vue'
}
next()
}
任何想法如何解决它?
这是因为 typescript 不知道实例的类型this
。尝试这样的事情:
(this as ProjectSandboxTs).findProjects()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句