S
S
sldo_ru2020-04-29 14:52:08
JavaScript
sldo_ru, 2020-04-29 14:52:08

How to hide a specific Vue element without binding to a variable?

There is a project with drop down lists (FAQ). I wanted to organize the disclosure of the list by clicking. I know how to do it in JS, but I would like to use Vue. How can I make it so that the list that I clicked opens. If you bind to one variable, then all will be opened.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-04-29
@sldo_ru

<template>
  <div v-for="(item, index) in items" :key="index">
    <span @click="item.open = !item.open">{{ item.question }}</span>
    <span v-if="item.open">{{ item.answer }}</span>
  </div>
</template>
<script>
export default {
  data: {
    faqs: [
      {
        open: false,
        question: '...',
        answer: '...',
      },
    ],
  },
}
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question