<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<my1></my1>
<my></my>
</div>
<script src="js/vue.js"></script>
<script>
var bus=new Vue();
Vue.component('my1',{
template:`
<div>
<button @click="wang">按钮</button>
</div>
`,
data:function(){
return{
num:'杨梦娇,小傻逼'
}
},
methods:{
wang:function(){
bus.$emit('on-message',this.num);
}
}
})
Vue.component('my',{
template:`
<div>
<p>{{num1}}</p>
</div>
`,
data:function(){
return{
num1:''
}
},
mounted:function(){
bus.$on('on-message',num2=>{
this.num1=num2
})
}
})
new Vue({
el:'#app'
})
</script>
</body>
</html>
网友评论