1 Star 0 Fork 0

myteam / vuedemo-279-3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
非父子.html 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
中博刘Kun 提交于 2020-03-27 16:29 . tt
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<tudou></tudou>
<digua><digua>
</div>
<script src="js/vue.js" type="text/javascript"></script>
<script>
//声明一条消息总线
Vue.prototype.$bus = new Vue()
var tudou = {
template:`
<div >土豆 {{message}}</div>
`,
data:function(){
return {
message : ''
}
},
//组件创建完成的函数 (组件声明周期中的一部分)
created(){
console.log(111)
//var _this = this
//this.$bus.$on('diguashuo',function(val){
// _this.message = val
//})
//es6语法中的箭头函数
this.$bus.$on('diguashuo',(val)=>{
this.message = val;
})
}
}
var digua = {
template:`
<div>地瓜
<button @click="sendToTudou">发信息给土豆</button>
</div>
`,
methods:{
sendToTudou(){
this.$bus.$emit('diguashuo',"土豆土豆,我是地瓜")
}
}
}
new Vue({
el:"#app",
components:{
'tudou' : tudou,
'digua' : digua
}
})
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/project270/vuedemo-279-3.git
git@gitee.com:project270/vuedemo-279-3.git
project270
vuedemo-279-3
vuedemo-279-3
master

搜索帮助