我对 vue 和 TypeScript 还很陌生,所以请原谅我可能相当微不足道的问题。
我使用 vue-super-eventbus
来触发组件树中的事件。到目前为止,将 vue 与 JavaScript 结合使用时,效果很好。
但是当我将我的文件迁移到 TypeScript 时,我遇到了一个问题,我不知道如何以及在何处使用 on
注册侦听器。
在 JS 中,我的组件如下所示:
export default {
name: "ComponentA",
//registering the eventlisteners
on: {
setParentVar(data) {
console.log(data)
}
}
}
现在,将我的文件迁移到 TS,它看起来像这样:
import { Component, Vue } from 'vue-property-decorator'
@Component({
components: {
ComponentB
}
})
export default class ComponentA extends Vue {
//class methods and variables here
}
但是当我像这样尝试在 on
中使用 @Component
注册我的事件侦听器时:
@Component({
components: {
ComponentB
},
on: {
setParentVar(data) {
console.log(data)
}
})
我得到 No overload matches this call.
我已经像这样在 main.ts 中导入了插件:
import EventBus from 'vue-super-eventbus'
Vue.use(EventBus)
谁能指出我正确的方向,我在这里不明白什么?