亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

How to detect clear button click event on v-select (vue-select)
P粉436688931
P粉436688931 2023-12-27 11:41:15
0
1
971

I am creating a dropdown menu in v-select and after selecting an option when clicking the clear button, I need to clear the dropdown menu and change the options array to the initial stage.

How to check if clear button(x) is clicked, I tried using on-change for getting the selected value and it works fine while @click etc. don't It works, please help me.

<template>
  <v-select
    v-model="selected"
    :reduce="(option) => option.id"
    :options="[
      { label: 'One', id: 1 },
      { label: 'Two', id: 2 },
    ]"
    @onChange="searchProduct"
    
  />
</template>

<script>
export default {
  data() {
    return {
      selected: 3,
    }
  },
 methods(){
  searchProduct(selected){
  console.log('selected value ',selected)
}

}
</script>

I was expecting some way to handle the dropdown clear event.

P粉436688931
P粉436688931

reply all(1)
P粉311464935

Since we don't have any explicit events yet, we can achieve this requirement by observing the v-model value.

watch: {
    selected(value) {
        if (!value) {
            // Your logic here
        }
    }
}

Live demonstration upon request :

Vue.component("v-select", VueSelect.VueSelect);

new Vue({
  el: "#app",
  data: {
    selected: 3
  },
  watch: {
    selected(value) {
      if (!value) {
        this.selected = 3;
      }
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-select/3.10.3/vue-select.js"></script>
<link rel="stylesheet" />
<div id="app">
  <v-select
    v-model="selected"
    :reduce="(option) => option.id"
    :options="[
      { label: 'One', id: 1 },
      { label: 'Two', id: 2 },
    ]"
  />
</div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template