[Vuejs]-How to use filter to search when press a button

0👍

const selected = ref('ALL')
const filteredList = computed(() => {
    return shows.value.filter((el) => selected.value === 'ALL' || el.category.includes(selected.value))
})

whenever you press the button, you only need to change selected ref.
filteredList computed will be executed whenever selected changes.


add this method in script setup.

const onClickChoice = (val) => {
    selected.value = val
}

and add @click like this.

<div class="choice-list">
  <div
    class="choice"
    v-for="(choice, index) in labels[activeIndex].choice"
    :key="index"
    @click="onClickChoice(choice)"
  >
    {{ choice }}
  </div>
</div>

-1👍

Current Situation:

Added above code, but no reaction when pressing the row2 buttons.
enter image description here

enter image description here

Leave a comment