基于:
https://forum.vuejs.org/t/passing-data-back-to-parent/1201 vue 按钮相关事件未触发
我有:
https://codesandbox.io/s/vigilant-mendeleev-hi4br?file=/src/components/GenericItem.vue
父组件监听子组件发出的事件:
mounted() {
this.$on("edit-category", (taskItemParam) => {
console.log("Received edit-category event with payload:", taskItemParam);
});
this.$on("delete-category", (taskItemParam) => {
console.log(
"Received delete-category event with payload:",
taskItemParam
);
});
},
孩子在哪里:
https://codesandbox.io/s/vigilant-mendeleev-hi4br?file=/src/components/EditCategory.vue
发出两个事件:
<div class="modal-body" @click="emitEditCategory()">
<slot name="name"> Edit Name </slot>
</div>
<div class="modal-body" @click="emitDeleteCategory()">
<slot name="delete"> Delete Category </slot>
</div>
methods: {
...
emitEditCategory() {
this.$emit("edit-category", this.taskItemLocal);
console.log("Emitting edit-category");
},
emitDeleteCategory() {
this.$emit("delete-category", this.taskItemLocal);
console.log("Emitting delete-category");
},
},
为什么事件没有到达父级?vue中事件的范围是什么(wrt child-to-parent depth)