vue3.0项目通过npm link引入其它vue3.0项目的组件时,其它项目的组件中一旦使用onMounted,injectHook时target为null,其它组件的setup为同步操作
Version
3.2.23
Reproduction link
Steps to reproduce
1.git clone https://github.com/thecoolbb/lerna-vue3-example 2.cd lerna-vue3-example 3.cd packages/client 4.npm install 5.npm link 6.cd ../manage 7.npm install 8.npm link client 9.npm run serve 执行上述命令会报下述错误 [Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
What is expected?
正常执行client组件中的onMounted内部逻辑
What is actually happening?
injectHook时因为target为null,所以不会执行onMounted内部的逻辑
之前使用git的submodule,当主项目调用子项目的vue3组件时,组件中一旦包含onMounted也会爆出这个错误。 当把子模块的组件移到主项目中时,错误消失。
4.npm install
Maybe you could skip this step, so that the vue
of the sub-component and the main component import
point to the same place. It seems like not vue's bug. You can ask questions on the forum, the Discord server or StackOverflow.