i want to remove elements from this array when they get selected but v-on:change is not the right option because when you select an item, the select value will change twice so the method will also get executed twice (two elements will be removed) i thought of making a new directive to do this job ,but i want to leave it as my last option ...thank you
new Vue({
el:"#app",
data :{
arr:['1','2','3','4'],
selected:""
},
methods :{
splice (){
this.arr.splice(this.arr.indexOf(this.selected),1)
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<select v-model="selected" @change="splice">
<option v-for="item in arr" >{{ item }}</option>
</select>
<div>
this was my attempt, but like i said it get executed twice because select value changes twice and also i want to do more stuff on item selection so maybe i should just make a directive
selectedis empty and when you useindexOfthat will returns -1 you're removing the last selected one