我使用 Vue-Dragula 进行拖放。当我放下时,它会触发方法:
mounted: function () {
this.$nextTick(function () {
Vue.vueDragula.eventBus.$on(
'drop',
function (args) {
console.log(this.championship);
}
);
}
现在 this.championship
是一个计算属性:
computed: {
championship(){
return this.championships.find((elem) => elem.championship == this.championship_id);
},
}
其中 championships
和 championship_id
是全局数据。
和console.log(this.championship);
返回undefined
现在,我简化并写下:
computed: {
championship(){
return 2;
},
}
和console.log(this.championship);
继续返回undefined
我的代码有什么问题???
最佳答案
使用箭头函数让你的 this
成为实际的 Vue 实例:
mounted () {
this.$nextTick(() => {
Vue.vueDragula.eventBus.$on(
'drop',
args => console.log(this.championship)
);
})
}
关于vue.js - 在 VueJS 中检索计算属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42840488/