I am trying to loop through and array of objects printing list items. I have a click listener which add a custom property the object and a class binding is dependent on that property value. Here is my code please have a look.
Html
<div class="row wi ony-bor-ans" v-if="q.ans" v-for="(ans,i) in q.ans" :key="i">
<div class="col-auto que-ans-main-ul">
<ul>
<li @click="voteOnAns(1,i)" :class="{voted:ans.ansVotedUp}">
<i class="fa fa-chevron-up"></i>
</li>
<li><span>{{i}}</span></li>
<li @click="voteOnAns(-1,i)" :class="{voted:ans.ansVotedDown}">
<i class="fa fa-chevron-down"></i>
</li>
</ul>
</div>
My vue method voteOnAns looks like this
voteOnAns(ansVoteType,i){
if(ansVoteType>0){
this.q.ans[i].ansVotedUp=true;
this.q.ans[i].ansVotedDown=false;
}else{
this.q.ans[i].ansVotedDown=true;
this.q.ans[i].ansVotedUp=false;
}
console.log(this.q.ans);
}
Here this.q.ans prints the specific object correctly.
Another interesting thing is, I am using vue chrome extension and there I see some time this new property added and sometime is they are not there in object. But console.log shows the object correctly.
Any help or explanation is highly appreciated. Thank you.