共计 541 个字符,预计需要花费 2 分钟才能阅读完成。
1. [Vue warn]: inject() can only be used inside setup() or functional components.
这个消息是提示我们,需要将引入的方法作为一个变量使用。以 vue-store 为例,如果我们按照如下的方式使用:
import UseUserStore from '../../store/modules/user'
const role = UseUserStore ().role
就会提示如上错误。但是,如果我们按照这样的方法使用,就不会报错了。
import UseUserStore from '../../store/modules/user'
const userStore = UseUserStore()
const role = userStore.role
2. [Vue warn]: Component inside renders non-element root node that cannot be animated.
这个 warn 是提示您,组件中的渲染元素没有全部包裹在一个 div 中,就像下面这样的:
只需要将这几个引入的足迹放在根 div 标签内即可:
当我们将渲染元素全部放在同一个 div 内,就没有 warn 提示了。
原文地址: vue3 的两个提示[Vue warn]: 关于组件渲染和函数外部使用
正文完