vue兄弟组件传值,接收值的时候,this指向有问题?
a.vue
import Bus from '../../utils/bus.js' //公共vue 传值
export default {
components: {
baidumap,
bmView
},
data () {
return {
zoom: 10,
address: '点我选择'
}
},
mounted () {
this.createdMap();
let that = this;
Bus.$on('addValue',function (argument) {
console.log(that)
if (argument) {
that.address = argument.ci_name
console.log(that)
}
})
console.log(this)
console.log(that)
}
}
b.vue
import Bus from '../../utils/bus.js'
export default {
data () {
return {
proshow:true,
cityshow:false,
countyshow:false,
townshow:false,
proArr: [],
cityArr: [],
countyArr: [],
townArr: []
}
},
methods: {
selectpro (item) {
if (item.ci_id == 36) {
Bus.$emit('addValue',item)
this.$router.go(-1);
return;
}
}
}
}
在a.vue中输出的this的指向为][2]][1]
bus.js中的 新vue实例
为何他们的_uid不一样 而且在_uid为3的实例中address数据是已经更改的,在_uid为50的实例中address的数据是没有更改的?
前两个和后两个不是一起执行输出的吧
我觉得你应该是
Bus.$emit('addValue',item)的时候触发了之前注册过的Bus.$on
this.$router.go(-1)的时候触发了a.vue的mounted