https://github.com/vuejs/docs...
vue-router/src/composables/globals.js
但是 vue-router
的代码依旧在使用 getCurrentInstance
?getCurrentInstance
有合适的替代方案吗?
https://github.com/vuejs/docs...
vue-router/src/composables/globals.js
但是 vue-router
的代码依旧在使用 getCurrentInstance
?getCurrentInstance
有合适的替代方案吗?
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
按照鱿鱼须的原话就是:
同时也给出了应该如何解决问题:
主要还是
getCurrentInstance
是一个内部的API,并不是公开的API
,使用内部API去实现一些业务功能,可能会因为后续Vue
的版本迭代而造成业务上的BUG
。并且Vue3
的Composition API
强调的就是业务的解耦和复用性,依赖组件实例属性并不是一个很好的开发方式。而
vue
相关生态的使用其实就是他们内部的事情了,他们有完善的测试用例可以跑测试,但是我们并没有,如果后续的某一个版本Vue
变更了这个API
,那么如果没有经过完整测试就部署上去的项目就会出现大规模的BUG
反馈了。阅读更多
Unable to report missing search result · Issue #1775 · vuejs/docs
Why
getCurrentInstance
is descriped as anti pattern in application code? · Issue #1422 · vuejs/docsgetCurrentInstance type not correct · Issue #12596 · vuejs/vue
Vue 3: Is getCurrentInstance() deprecated? - Stack Overflow