console
Vue.component('parent-component',{
template: `
<div>
<child-one-component @updateChildTwo="updateChildTwo">
</child-one-component>
<child-two-component :msg="msg">
</child-two-component>
</div>
`,
data(){
return {
msg: 'child-two-component'
}
},
methods:{
updateChildTwo(){
this.msg = "child-two 组件更新了";
}
}
});
Vue.component('child-one-component',{
template: `
<div>
<button @click="updateChildTwo">child-one 更新兄弟组件</button>
</div>
`,
methods:{
updateChildTwo(){
this.$emit('updateChildTwo')
}
}
});
Vue.component('child-two-component',{
template: `
<div>
{{ msg }}
</div>
`,
props: {
msg: String,
}
});
new Vue({
el: '#root',
})
<script src="https://unpkg.com/vue"></script>
<div id="root">
<parent-component>
</parent-component>
</div>