bus.js的代码
import Vue from 'vue'
export default new Vue()
在页面中引用
import bus from '../router/bus.js'
页面创建时监听
created() {
bus.$on('num',(num) => {
console.log('the num is',num);
this.num = num
})
},
发送数据
go_shequ() {
this.$router.push(`/product?id=${this.shequ.productId}&productName=${this.shequ.productName}&productSmallUrl=${this.shequ.productSmallUrl}`)
bus.$emit('num',5)
},
go_yanglao() {
this.$router.push(`/product?id=${this.yaolao.productId}&productName=${this.yaolao.productName}&productSmallUrl=${this.yaolao.productSmallUrl}`)
bus.$emit('num',2)
},