Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
How to hide an element from a list if clicked twice without toggling in a vue nuxt application

I have got a clickable list in a Vue/Nuxt application. When one item is selected, a little tick mark appears. I would like to be able to unselect an item (the tick mark to disappear) if the item is clicked again. If I click on another item, I would like this item to be selected and the previously selected item to unselect (only one item can be selected). So far, if I try to select another item, I need to click twice because the first click will only unselect the first selected item and the second click will select the new item. Any idea ??

<template>
  <div
    v-for="(item, itemIndex) in list"
            :key="itemIndex"
            @click="onClick(itemIndex)"
  >
    <div>
      <div v-if="activeIndex == itemIndex && selected === true">
        <TickMark />
      </div>
      <Item />
    </div>
  </div>
</template>

<script>

export default {
    props: {
        questionModules: {
            required: true,
            type: Array,
        },
    },
    data() {
        return {
            activeIndex: null,
            selected: false,
        }
    },
    methods: {
        onClick (index) {
            this.activeIndex = index
            this.selected = !this.selected
        },
    },
}
</script>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

because you don't need to change positions or sort the list - keeping the selected index is just fine, do it like this:

<template>
  <section
    class="items-list">
    <template v-for="(item, itemIndex) in list"
            :key="itemIndex" >

      <TickMark v-if="activeIndex === itemIndex 
       @click="selectItem(itemIndex)"  /> // by clicking on the mark - it will toggle the selection


      <Item />

    </template>
  </section>

</template>

<script>

export default {
    props: {
        questionModules: {
            required: true,
            type: Array,
        },
    },
    data() {
        return {
            activeIndex: null
        }
    },
    methods: {
        selectItem (index) {
            this.activeIndex = index
        },
    },
}
</script>

I've changed the architecture of the DOM so it will be without all the un-necessary elements

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda