see an example,code at the bottom of the problem for permission control. If there are not enough permissions, there is no element.
I"d like to ask the hero to take a look at it:
- Why do you need to do
Object.defineProperty(comment, "setAttribute", {
value: () => undefined,
});
2 do not understand what vnode is and what is its use?
Vue.directive("permission", (el, binding, vnode) => {
if (!isUserGranted(binding.value)) {
// replace HTMLElement with comment node
const comment = document.createComment(" ");
Object.defineProperty(comment, "setAttribute", {
value: () => undefined,
});
vnode.elm = comment;
vnode.text = " ";
vnode.isComment = true;
vnode.context = undefined;
vnode.tag = undefined;
vnode.data.directives = undefined;
if (vnode.componentInstance) {
vnode.componentInstance.$el = comment;
}
if (el.parentNode) {
el.parentNode.replaceChild(comment, el);
}
}
});