new Vue
<template>
<div id="app">
<aaa/>
<hr>
<bbb/>
</div>
</template>
<script>
import Vue from 'vue'
var Event = new Vue();
export default {
name: 'App',
data(){
return{
}
},
components:{
aaa:{
template:`<div>我是aaa组件<p>{{msg}}</p></div>`,
data(){
return{
msg:'msg-aaa'
}
},
mounted(){
var that = this;
Event.$on('zxc',(val)=>{
this.msg = val;
})
}
},
bbb:{
template:`<div>我是bbb组件<p>{{msg}}</p><input v-model="msg" @keyup.13="eemmiitt"/></div>`,
data(){
return{
msg:'msg-bbb'
}
},
methods:{
eemmiitt(){
console.log(this.msg);
Event.$emit('zxc',this.msg)
}
}
}
}
}
</script>
<style>
</style>