EventBusイベントカー(イベントバス)によるコンポーネント通信
594 ワード
// bus
let bus = {
install($){
// vue getBus setBus
$.prototype.getBus = this.get
$.prototype.setBus = this.set
},
get(key){
// bus , , undefined
if(this.bus){
return this.bus[key]
}else{
return undefined
}
},
set(key,value){
// bus , ,
if(!this.bus){
this.bus = {}
}
this.bus[key] = value
}
}
Vue.use(bus);
// : vue main .
// 。
created(){
this.setBus('name','xiaoming');
console.log(this.getBus('name'));
}