bus(兄弟组件间传值)

1.bus.js
import Vue from ‘vue’
export default new Vue;

1.兄弟组件a



import Bus from ‘./bus.js’
export default {
data() {
return {
message: ‘’"
}
},

methods: {
bus () {
Bus.$emit(‘msg’, ‘我要传给兄弟组件们,你收到没有’)
}
}
}

3.兄弟组件b


{{message}}



import Bus from ‘./bus.js’
export default {
data() {
return {
message: ‘’
}
},
mounted(){
 let self = this;
Bus.$on(‘msg’, (e) => {
console,log(e)
this.message = e
})
}
}

你可能感兴趣的:(bus(兄弟组件间传值))