我正在使用 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()
}
任何想法如何解決它?
uj5u.com熱心網友回復:
這是因為 typescript 不知道實體的型別this。嘗試這樣的事情:
(this as ProjectSandboxTs).findProjects()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/461776.html
標籤:打字稿 Vue.js vue 类组件 vue-property-decorator
上一篇:專案在vue中沒有正確對齊
