What is the best way for vue to handle multiple containers showing and hiding?

//html
<div v-for="(item, index) in data" :class="["container", {"show": firstSwitchArr[index]}]">

//js
data: {
     firstSwitchArr: [true, false, false, false, false],
     data: data
},
methods:{
   switchShow(index) {
          this.$set(this.firstSwitchArr, index, !this.firstSwitchArr[index])
    }
}

//csss
.container{display:none}
.container.show{display:block}

vue project has a page, there are many containers for displaying data, which can be shown and hidden and divided into primary list and secondary list. The containers for displaying data are traversed through data, and there can be as many as you want. The method I implemented above does not quite meet the requirements. Is there a better way to implement it?

May.05,2022

traverse the array into objects key for data value for state


ui show to vue to do, considering that you can often change using v-show, data format {..., show: true or false}, switch the value of show through events, the value of this attribute is used for v-show


it is recommended to use the following data format to control the display and hiding through open true or false

[
    {
        label: 'A1',
        value: 'A1',
        open: true,
        children: [
            {
                label: 'A1-1',
                value: 'A1-1'
            }
        ]
    },
    {
        label: 'A2',
        value: 'A2',
        open: false
    }
]
Menu