let bus = new Vue()
Vue.component('my-demo', {
template: `
<div class='father'>
爱你{{obj}}
<button @click='fn'>按钮</button>
</div>
`,
data() {
return {
obj: {
name: 'zs',
age: 18
}
}
},
methods:{
fn(){
bus.$emit('send',this.obj)
}
}
})
Vue.component('my-demo1', {
template: `
<div class='son'>
哟哟 {{msg}}
</div>
`,
data() {
return {
msg: 'asdf'
}
},
mounted() {
bus.$on('send', (msg) => {
console.log(msg);
this.msg = msg
})
}
})
let vm = new Vue({
el: '.app',
}
)
$emit()这个方法好像只能通过事件里面去使用,不能放到钩子函数里面使用,请问一下这是为什么