Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
Vuetify V-Chip Alphabetical Sort?

Hey Iam Trying To Sort Multiple V-Chips By Alphabetically. Any idea guys?

Down Below Is the Code Iam Trying To Display all my v-chips alphabetically sorted Should my array be sorted or is there any property in vuetify which does the work done? Any help would be appreciated

   <template>

        <div class="pa-4">
          <v-chip-group
            active-class="primary--text"
            column
          >
            <v-chip
              v-for="tag in tags"
              :key="tag"
            >
              {{ tag }}
            </v-chip>
          </v-chip-group>
        </div>
     
</template>

<script>
  export default {
    data: () => ({
      tags: [
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
      ],
    }),
  }
</script>
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can simply achieve it by using Array.sort() method. You can sort either in mounted() lifecycle hook or directly in template itself inside v-for directive.

Demo :

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    tags: [
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
      ]
  })
})
<script src="https://unpkg.com/vue@2.x/dist/vue.js"></script>
<script src="https://unpkg.com/vuetify@2.6.4/dist/vuetify.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/vuetify@2.6.4/dist/vuetify.min.css"/>
<div id="app">
  <v-app id="inspire">
    <v-chip-group active-class="primary--text" column>
      <v-chip v-for="tag in tags.sort()" :key="tag">
        {{ tag }}
      </v-chip>
    </v-chip-group>
  </v-app>
</div>

about 4 years ago · Santiago Trujillo Relatório

0

Sorting it directly in the component resulted in a infinite update loop in the render function for me. This solves it:

<v-chip-group active-class="primary--text" column>
    <v-chip v-for="tag in [...tags].sort()" :key="tag">
        {{ tag }}
    </v-chip>
</v-chip-group>
about 4 years ago · Santiago Trujillo Relatório

0

I would personnaly use a computed property to sort the data.

Then the logic of the sort function will be separated from the template and if you have more complex object with a more complex sort method that would be more readable.

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  computed: {
     tagsSorted(){
        return this.tags.sort()
     }
  },
  data: () => ({
    tags: [
        'Work',
        'Home Improvement',
        'Vacation',
        'Food',
        'Drawers',
        'Shopping',
        'Art',
        'Tech',
        'Creative Writing',
      ]
  })
})
<script src="https://unpkg.com/vue@2.x/dist/vue.js"></script>
<script src="https://unpkg.com/vuetify@2.6.4/dist/vuetify.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/vuetify@2.6.4/dist/vuetify.min.css"/>
<div id="app">
  <v-app id="inspire">
    <v-chip-group active-class="primary--text" column>
      <v-chip v-for="tag in tagsSorted" :key="tag">
        {{ tag }}
      </v-chip>
    </v-chip-group>
  </v-app>
</div>

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda