大佬们,小弟这是哪里报的错
来源:4-5 非父子组件间的传值
星期9
2018-04-09
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="../../vue.js"></script>
<title>非父子组件间的传值(Bus/总线/发布订阅模式/观察者模式)</title>
</head>
<body>
<div id="app">
<!-- 子组件(兄弟组建之间)之间的传值 -->
<child content="haha"></child>
<child content="heihei"></child>
</div>
<script>
Vue.prototype.bus = new Vue();
Vue.component('child', {
data: function () {
return {
selfContent = this.content
}
},
props: {
content: String
},
template: '<div @click="btnFuc">{{selfContent}}</div>',
methods: {
btnFuc: function () {
this.bus.$emit('change', this.selfContent);
}
},
mounted: function () {
var this_ = this;
this.bus.$on('change', function (msg) {
this_.selfContent = msg
})
}
})
var vm = new Vue({
el: "#app"
})
</script>
</body>
</html>

写回答
2回答
-
23行,等号换成冒号
012018-04-10 -
Dell
2018-04-09
截图我看下
012018-04-09
相似问题
大佬们,小弟这是哪里报的错
回答 4
Swiper版本是2.6.7,却依然报错
回答 3
template报错eslint
回答 3
进入某个id页面,刷新会报错
回答 3
swiper的背景色不显示
回答 3