Vue.prototype.bus = new Vue();
Vue.component("child",{
template: '<div @click="handleClick">{{selfContent}}</div>',
props: {
content: String
},
data() {
return {
selfContent: this.content
}
},
methods: {
handleClick() {
this.bus.$emit("change", this.selfContent);
}
},
mounted() {
this_ = this;
console.log(this);
this.bus.$on("change", function(value) {
console.log("value:",value);
});
}
});
var app = new Vue({
el: '#app',
mounted() {
this.bus.$on("change", function(value){
console.log(value);
})
}
});
vue中的Bus/总线/发布订阅/观察者模式
猜你喜欢
转载自blog.csdn.net/qiguoqi777/article/details/105716622
今日推荐
周排行