Answer the question
In order to leave comments, you need to log in
How to update a variable only in the current vue iteration?
Hello to all!
There is such a simple code for the vue component
<li v-for="(comment, index) in comments" :key="index" class="c">\
<textarea @click="clickTextarea()" :style="clicked ? active : passive"></textarea>\
</li>\
data: function () {
return {
clicked : false,
active: 'height:auto; ',
passive: 'height:22px; '
}
},
methods: {
clickTextarea: function() {
this.clicked = true;
}
}
Answer the question
In order to leave comments, you need to log in
Each comment should have its own clicked, not just one at all.
Add a property to the component - an active comment:
data: () => ({
...
activeComment: null
})
<li v-for="comment in comments">
<textarea
@click="activeComment = comment"
:style="activeComment === comment ? active : passive"
></textarea>
</li>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question