Vue switching class encountered a problem, can not each switch together?

making a folding panel like this

the requirement is that after clicking on the title, the down arrow on the right will be expanded and icon will switch up to the up arrow

. The problem with

is that every icon I expand will switch up and down together.

but my goal is to switch as long as the one I click on, not all of them.

beginner VUE wants to ask how to solve this problem

my program looks like this (only part of it is retrieved)

<i v-bind:class="{ "el-icon-arrow-down" : isA, "el-icon-arrow-up": !isA}" @click="onClick()"></i>

js

data() {
 return {isA: true}
},
methods:{
onClick(inputKey) {this.isA = !this.isA;},
}
Mar.22,2021

We always talk about the separation of bound variables, and now they are all bound to an isA, which is naturally the result.
for example, change it to an array:

<i v-bind:class="{ 'el-icon-arrow-down' : isA[0], 'el-icon-arrow-up': !isA[0]}" @click="onClick(0)"></i>
<i v-bind:class="{ 'el-icon-arrow-down' : isA[1], 'el-icon-arrow-up': !isA[1]}" @click="onClick(1)"></i>
...
data() {
 return {isA: [false,false,false]}
},
methods:{
onClick(index) {this.isA[index] = !this.isA[index];},
}

if there are any irregularities, please forgive me and correct them. Thank you.


you can bind class by adding a property to each object in the array that you traverse the list. Or, as above, define a collection of Boolean values of equal length.


I think you can learn from the highlighting of the navigation bar

Menu