I want to create a v-if like directive, but i can't find a way to remove element so i hide the element like this..
<Button v-check="'aaa'" type="primary">aaa</Button>
<Button v-check="'bbb'" type="primary">bbb</Button>
Vue.directive('check', {
bind(el, binding, vnode, old) {
if (binding.value === 'aaa') {
el.style.display = 'none'
}
}
})
i want to remove the element totally Is there any way that i can remove the element?
To remove an element from a list with Vue. js, we can use the JavaScript array splice method. to add the removeElement method that takes the index of the item we want to remove from the this. items array.
Deleting elements in an array maintains reactivity in Vue when done right. These arrays can be local variables in a component, or state variables in Vuex - the behaviour is the same. We just use the standard pop and shift to delete elements in the array.
ok, i find a way
Vue.directive('check', {
inserted(el, binding, vnode, old) {
if (binding.value === 'aaa') {
vnode.elm.parentElement.removeChild(vnode.elm)
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With