美文网首页
Runtime directive used on compon

Runtime directive used on compon

作者: w晚风 | 来源:发表于2022-11-24 18:02 被阅读0次

控制台警告提示信息

控制台警告Runtime directive used on component with non-element root node. The directives will not function as intended.
如下


image.png

原因和解决

意思是自定义指令不能放到组件上,而是要放到自有的元素上,也就是这里用到的v-show,v-if 不能放在自定义组件上,而是放在原来就有的标签上,所以这里套了一层div
比如之前的是这样子,v-show指令用在了自定义组件UserAdd身上,就警告了

<UserAdd v-show="materialType" />

解决

外面套一层不是自定义组件的元素就可以,我这里套了一层div,你也可以嵌套一层template

<div v-show="materialType">
  <UserAdd />
</div>

或者

<template v-show="materialType">
  <UserAdd />
</template>

相关文章

网友评论

      本文标题:Runtime directive used on compon

      本文链接:https://www.haomeiwen.com/subject/lwsxfdtx.html