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