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

174
Vistas
Vue3 composition API accordion menu, problem with showing data

I try to show the data when it is true, but it doesn't work. I want to make an accordion menu (after clicking on a question, toggle an open property and show the answer if it's true)

Here is code:

<div class="accordion">
<h1 class="title">Frequently asked questions</h1>
<div class="wrapper">
    <div class="card" v-for="(item, i) in dataBase" :key="i">
      <div class="card-header" @click="item.open = !item.open">
        <h1>{{item.q}}</h1>
      </div>
      <div class="card-body" v-show="item.open">
        {{item.d}}
      </div>
    </div>
</div>

And data:

const dataBase = [{
  q: 'How much does it cost?',
  d: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
  open: false,
},
  {
    q: 'How it works?',
    d: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
    open: false,
  }]

Can anyone help and explain why in the console log it changes to true => false and vice versa, but doesn't show the data when it's true? Im new in Vue.

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

0

your code is working bro. i runned on my computer.

if you asked 'why true->false and false->'. true and false is boolean variable.

<div class="card-header" @click="item.open = !item.open">

and this line you did

item.open = !item.open // if item.open is true then here is false.
item.open = !item.open // if item.open is false then here is true.

what is this exclamation(!) in vue ?

!(false) // true
!(true) // false
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your dataBase property is not reactive, you should use ref to make it reactive :

import {ref} from 'vue'
const dataBase = ref([{
  q: 'How much does it cost?',
  d: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
  open: false,
},
  {
    q: 'How it works?',
    d: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
    open: false,
  }])

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