I've been through the vue.js events section on events but it seems to only give examples of how to listen to events using the vm.$on handler within html. Between that and the new changes for 2.0 I'm unsure how to simply transmit a event from child -> parent.
我需要传输一个事件,因为在父母接收后,我想把它广播给另一个子元素.
我使用的是单页组件,这是我的设置:
// parent
export default {
mounted: function () {
this.$on('myEvent', function (msg) {
console.log('caught in parent', msg)
});
},
components: {
'child': child,
},
}
// child
this.$emit('myEvent', true)
我如何在父vm上接收此事件?注意,我不想在html中使用$on.我希望事件接收逻辑在虚拟机中的应该位置.
谢谢