首页 > 其他分享 >[Vue3] 组件上的ref不能与组件名相同

[Vue3] 组件上的ref不能与组件名相同

时间:2023-03-14 19:13:08浏览次数:44  
标签:Vue warn 引入 vue Vue3 组件 ref

情景

image-20230314173244434

image-20230314173301290

image-20230314173329408

关键

  1. 组件没有正确引入
  2. 函数无限递归

解决

如果在网上搜索[Vue warn]: Component is missing template or render function. [Vue warn]: Invalid vnode type when creating vnode: null. .

可能会找到关于组件没有正确引入的解决方法,主要是:

  1. 引入组件的时候,组件的路径结尾的.vue不要省略。
  2. 引入组件的时候,要使用规范的驼峰命名法。

我使用的是vite,似乎会自动引入组件,即不需要写import ComponentName from '@/components/...;'

我检查之后,发现是:

我为了获取组件的DOM节点,使用了ref,但是组件上的ref和组件名重复了:

<MyComponent ref="myComponent"/>

这样似乎是会影响到vue的组件管理,于是导致了错误。

我将ref改为myComponentRef之后就可以正常运行了。

标签:Vue,warn,引入,vue,Vue3,组件,ref
From: https://www.cnblogs.com/feixianxing/p/vue-import-ref-component-name.html

相关文章