Javascript 侦听子组件中不工作的事件
我有一个父组件:Javascript 侦听子组件中不工作的事件,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我有一个父组件: export default { name: 'DashboardCommon', created() { console.log('CommonComponent'); this.storeSubscriber = this.$store.subscribe(mutation => { if ( mutation.type === `product/addToCart
export default {
name: 'DashboardCommon',
created() {
console.log('CommonComponent');
this.storeSubscriber = this.$store.subscribe(mutation => {
if (
mutation.type === `product/addToCart`
) {
this.$parent.$emit('addToCart');
console.log('Emit event');
}
});
},
beforeDestroy() {
this.storeSubscriber();
}
};
我的子组件比扩展的仪表板公用
export default {
extends: DashboardCommon,
name: 'Product',
components: {
Filter
},
created() {
this.$on('addToCart', () => {
console.log('Changed');
});
}
};
我放置了一些日志,并从
仪表板common
发送事件,但这些事件不是侦听子组件。因此,我在控制台中有Emit事件
,但从未更改过日志:(.您对此有何想法?请提前通知Thx。这不是父项?只是这个。$Emit('addToCart')
由于扩展