[Vuejs]-When I delete one in the v-expansion-panel it opens the next one for me. How to undo it

0๐Ÿ‘

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    active: null,
    test: [1, 2, 3, 4, 5]
  }),
  methods: {
    del(index) {
      this.test.splice(index, 1)
      this.active = null
    }
  }
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<div id="app">
  <v-app>
    <v-main>
      <v-container>
        <v-expansion-panels v-model="active">
          <v-expansion-panel v-for="(t, index) in test" :key="index">
            <v-expansion-panel-header>
              item
            </v-expansion-panel-header>
            <v-expansion-panel-content>
              <v-col cols="4">
                <v-btn text color="red" @click="del(index)">delete{{t}}</v-btn>
              </v-col>
            </v-expansion-panel-content>
          </v-expansion-panel>
        </v-expansion-panels>
      </v-container>
    </v-main>
  </v-app>
</div>

Using value prop:

Controls the opened/closed state of content in the expansion-panel. Corresponds to a zero-based index of the currently opened content.

Set this.active = null after each deletion to keep the panel closed.

Leave a comment