【发布时间】:2019-01-15 10:11:08
【问题描述】:
我正在 Vue2 中使用带有子组件的 vue-component 创建一个组件
<note :bus="bus" :itemId="selectedId"></note>
看起来像这样
<textarea v-model="text"></textarea>
子组件注册到事件
created() {
if (this.bus != null) {
this.bus.$on('store', () => {
this.store()
});
}
}
组件确实
this.bus.$emit('store')
在所有子组件中触发存储。
现在第一次 store 被调用一次。在第二次编辑时,它被调用了两次,等等。所以我猜每次都会创建更多的子组件。或者我必须从公共汽车上注销?还是我在错误的生命周期挂钩中注册总线?
【问题讨论】:
标签: typescript vue.js vuejs2 vue-component