我想创建一个类似 v-if 的指令,但我找不到删除元素的方法,所以我像这样隐藏了元素..
<Button v-check="'aaa'" type="primary">aaa</Button>
<Button v-check="'bbb'" type="primary">bbb</Button>
Run Code Online (Sandbox Code Playgroud)
Vue.directive('check', {
bind(el, binding, vnode, old) {
if (binding.value === 'aaa') {
el.style.display = 'none'
}
}
})
Run Code Online (Sandbox Code Playgroud)
我想完全删除元素 有什么方法可以删除元素吗?
好的,我找到了方法
Vue.directive('check', {
inserted(el, binding, vnode, old) {
if (binding.value === 'aaa') {
vnode.elm.parentElement.removeChild(vnode.elm)
}
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3712 次 |
| 最近记录: |