在封装自定义指令 v-permission 时发现 自定义指令中的el.removeChild 与 v-if 会报错如下:
DOMException: Failed to execute ‘insertBefore’ on ‘Node’: The node before which the new node is to be inserted is not a child of this node.
个人的解决方案是v-if 跟 v-permission 不要放在同一个节点下或者将v-if改为v-show
例如原本写法 :
<a-button
type=”primary”
v-permission=”[‘client:add’, ‘client:open’]”
v-if=”!userId”
>
新增
</a-button>
改为:
<template v-if=”!userId”>
<a-button
type=”primary”
v-permission=”[‘client:add’, ‘client:open’]”
>
新增
</a-button>
</template>
或者改为
<a-button
type=”primary”
v-permission=”[‘client:add’, ‘client:open’]”
v-show=”!userId”
>
新增
</a-button>