Vue.prototype.bus=new Vue(); Vue.component('child',{
template:`<div @click='handleClick'>{{text}}</div>`,
props:{
content:[String,Number]
}, data(){ return {
text:this.content
}
},
methods:{
handleClick(){ this.bus.$emit('change',this.text)
}
},
mounted(){ var _this=this
console.log(_this); this.bus.$on('change',function (msg) {
_this.text=msg
console.log(this);
})
}
}) var vm = new Vue({
el:"#app",
})上面代碼中的 this.bus.$on('change',function (msg) { _this.text=msg
console.log(this);
})
}里面的回調函數(shù)里面的this到底是指向誰?希望大佬幫忙解答一下,謝謝
添加回答
舉報
0/150
提交
取消