vue 和 vue-property-decorator.TS 错误中的错误
我正在使用 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) {...
}
但是,当我尝试在钩子中调用组件的方法时,我会收到打字稿错误: 属性“ FindProjects”在类型的“ VUE”上不存在
beforeRouteUpdate(to, from, next) {
if (!isEqual(to.query, from.query)) {
this.findProjects() // <== Property 'findProjects' does not exist on type 'Vue'
}
next()
}
任何想法如何修复它?
I'm writing application using Vue 2/typescript and vue-property-decorator. In my component I use beforeRouteEnter/beforeRouteUpdate hooks. My component has method findProjects, and I want to invoke this method in my beforeRouteUpdate hook.
My component:
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) {...
}
But when I try to invoke component's method in my hook, I get typescript error:
Property 'findProjects' does not exist on type 'Vue'
beforeRouteUpdate(to, from, next) {
if (!isEqual(to.query, from.query)) {
this.findProjects() // <== Property 'findProjects' does not exist on type 'Vue'
}
next()
}
Any ideas how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为Typescript不知道该实例将是哪种类型。尝试这样的事情:
It is because typescript doesn't know what type of instance
this
is going to be. Try something like this: