1
我想学习vue 2,但我被卡住了,有人可以帮我解释为什么我无法在事件关闭中访问这个组件? 在控制台中没有错误认为它不会呈现为什么我无法从闭包访问vuejs实例变量?
也许无用的信息: 通天的WebPack,VUE装载机,事件总线的工作虽然不是第一次了,我supose该组件没有创建依旧,但我认为这不是真正的问题
<template>
<div class="w3-row-padding">
<div class="w3-pannel">{{categoryName}}</div>
<categoria-admin v-for="number in 9"></categoria-admin>
</div>
</template>
<script>
import Bus from '../Classes/Bus';
export default {
data: function() {
return {
//Bind vari to template doesn't work either
vari: "varivari"
};
},
//tried with oncreate too
mounted: function() {
this.vari = "foo";//it works
// I tried with es5 passing this through a variable, doesn't work either
Bus.$on('categoria-item-selected', (category) => {
console.log("entering closure");// this get printed
this.vari = "ha funcionado" // doesn't work
this.updateVari('ha funcionado');// doesnt work
console.log(this.vari); // prints ha funcionado , but in template
//is not reflected and with chrome tool either
});
},
computed: {
categoryName : function() {
return this.vari;
}
},
methods: {
updateVari: function (value){
this.vari = value;
}
}
}
</script>
巴士是什么?它是一个Vue对象吗?如果你在事件处理程序中使用console.log(this),它会记录什么? – Bert