我碰到了一个v-if和自定义指令挺有趣的问题,不知道是不是bug #13742
Closed
yuanzengding-1234
started this conversation in
General Discussions
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
A reproduction for this https://stackblitz.com/edit/vitejs-vite-jazt6epq?file=src%2Fcomponents%2FDemoCompunent.vue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
我们项目中需要自定义指令通过权限来判断这个dom存不存在,当权限没有的时候会调用el.remove()来删除这个dom,这个问题就是出在没有权限的时候,我极度简化代码后大概是这样
图片中的status控制着template渲染,v-del-dom会在mounted后删除div。
下面是调用这个组件的代码
就是status状态在1秒后变成状态1
现在会有报错下面是报错截图
当DemoCompunent组件中代码调整为下面这样,他就不报错了
我跟了代码后发现vue的这行代码会把那个v-if所在的template当成一个元素

当我改变status后 找这个template父元素的时候发现这个父元素是个null,但是没有理解为什么内部两个元素的时候就没有报错了,就很奇怪
Beta Was this translation helpful? Give feedback.
All reactions