Vue3踩坑记录
'defineProps' is not defined
vue3+webpack5+ts
# 版本8以上
$ npm i eslint@latest -D
$ npm i eslint-plugin-vue@latest -D
# 后续若出现TypeError: eslint.CLIEngine is not a constructor错误执行以下命令
$ npm uninstall @vue/cli-plugin-eslint
TypeError: eslint.CLIEngine is not a constructor
vue3+webpack5+ts
$ npm uninstall @vue/cli-plugin-eslint
用$refs获取子组件
-
像在vue2中一样,给组件设置
ref="xxx"项我是子组件 -
vue3中通过ref来获取,变量名需与
ref='xxx'一致我是子组件 -
在onMounted函数中打印获取到的子组件,否则打印出
undefined我是子组件 -
为了使用子组件中的变量或方法,需要在子组件中使用
defineExpose编译器宏子组件内部 -
父组件调用时用
child.value.xxx来调用我是子组件