vue兄弟组件传值,接收值的时候,this指向有问题?a.vueimport 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.vueimport 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的指向为bus.js中的 新vue实例为何他们的_uid不一样 而且在_uid为3的实例中address数据是已经更改的,在_uid为50的实例中address的数据是没有更改的?
2 回答

jeck猫
TA贡献1909条经验 获得超7个赞
前两个和后两个不是一起执行输出的吧
我觉得你应该是
Bus.$emit('addValue',item)的时候触发了之前注册过的Bus.$on
this.$router.go(-1)的时候触发了a.vue的mounted
添加回答
举报
0/150
提交
取消