<div ref="filters"></div>
<div ref="available">
<span class="badge badge-pill" @click="add_filter">Label</span>
</div>
export default{
data(){
...
},
methods:{
add_filter: function(event){
this.$refs.filters.appendChild(event.target)
event.target.removeEventListener('click', this.add_filter)
event.target.addEventListener('click', this.remove_filter)
},
remove_filter: function(event){
this.$refs.available.appendChild(event.target)
event.target.removeEventListener('click', this.remove_filter)
event.target.addEventListener('click', this.add_filter)
}
}
So, removeEventListener doesn't work is this case. There's any way that I can accomplish to "toggle" the @click event?
toggle_filterand pass a parameter so you know if you should append to filters or available, no reason to remove an event listener and re-add one<span class="badge badge-pill" @click="toggle('filters', $event)">Label</span>the first time works and the span goes to filters, but when a click again it doesn't go back to available because it still have the@click="toggle('filters', $event)". How do I change the first parameter?