Uncaught TypeError: Cannot read property 'items' of undefined
不论用this.items还是 items 都无法读取,并且奇怪的是type==1 里面可以用this.items 读取到data里面的items 但是type==2里面就不行了 不知道为啥 求教我
<button type="button" id="allNotes" v-on:click="showNote(1)">
<span>allNotes</span>
</button>
<button id="Favorites" v-on:click="showNote(2)">
<span>Favorites</span>
</button>
export default {
data:function(){
return{
items:this.$parent.Notes,
}
},
methods:{
showNote:function(type){
this.items='';
if(type==1){
this.items=this.$parent.Notes;
}
if(type==2){
this.$parent.Notes.forEach(function(c){
if(c['favorite']){
console.log(this.items);
}
});
}
}