1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

vue.jsでシンプルなアコーディオンメニュー(2)

Posted at

配列にあったら表示、無かったら非表示する

index.vue
// Composition API
const showBox = ref([])
const open = (data) => {
  if (showBox.value.includes(data) === false) {
    showBox.value.push(data)
  } else {
    showBox.value = showBox.value.filter(n => n !== data)
  }
}
index.vue
<div @click="open('q1')">
    質問
</div>
<div v-if="showBox.includes('q1')">
    答え
</div>
<div @click="open('q2')">
    質問
</div>
<div v-if="showBox.includes('q2')">
    答え
</div>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?