我将 vue-class-component 与 TypeScript 一起用于我的 Vue 项目。我有它的组件和 Mixin:
// MyComp.vue
import Component, { mixins } from 'vue-class-component'
import MyMixin from './mixin.ts'
@Component
export class MyComp extends mixins(MyMixin) {
compValue: string = 'Hello';
}
// mixin.ts
import Vue from 'vue'
import Component from 'vue-class-component'
@Component
export default class MyMixin extends Vue {
created() {
console.log(this.compValue); // TS2339: Property 'compValue' does not exist on type 'MyMixin'.
}
}
它可以工作,但 TypeScript 抱怨缺少属性“compValue”。如何解决这个问题?