मैं एक घटक बनाना चाहता था जो माउस छवि पर होने पर टेक्स्ट-बॉक्स प्राप्त करता है।VueJS v-if = array [index] काम नहीं कर रहा है
नीचे HTML टेम्पलेट है।
<section class="item-container" v-for="(item, index) in items">
<div class="image-box" @mouseenter="changeStatus(index)">
<img class="image" src="item.link" alt>
</div>
<div class="text-box" @mouseleave="changeStatus(index)" v-if="show[index]">
<h4>{{ item.name }}</h4>
<p>{{ item.content }}</p>
</div>
</section>
और नीचे app.js
new Vue({
el: '#app',
data: {
show: [false, false, false],
items: [
{
name: 'Author 1',
content: 'Content 1'
},
{
name: 'Author 2',
content: 'Content 2'
},
{
name: 'Author 3',
content: 'Content 3'
}
]
},
methods: {
changeStatus: function(index) {
this.show[index] = !this.show[index];
console.log(this.show);
console.log(this.show[index]); // console gets it as expected
}
}
});
जब मैं कोड ऊपर निष्पादित, मैं प्राप्त कर सकते हैं कि इस शो संपत्ति बदल गया है। हालांकि, वी-अगर अपडेट नहीं किया गया है। क्या हम v-if के लिए सरणी [अनुक्रमणिका] का उपयोग नहीं कर सकते हैं या इसके लिए कोई अन्य कारण है?
क्या आप अलग 'शो' सरणी के बजाय प्रत्येक 'आइटम' पर बुलियन मान रखने का विरोध कर रहे हैं? – mrogers