Comments (1)
都说provide/inject可以替代vuex,但是provide/inject貌似只能在组件的setup选项内使用吧?我如果想在其他地方使用就不行了。举个很常见的业务场景:
axios请求拦截器里给所有请求在请求头里带上token,用vuex我可以在拦截器逻辑所在的js文件里引用store。但是provide/inject在这里就用不了了吧
你好,刚看到你提的问题啊,我先说下的观点啊,第一点:provide和inject是你说的情况不假,仅局限于vue中去使用,这是没有问题的,但是他起的作用仅仅是传递的一个效果,一边注入,一边依赖,这个是和数据没有关系的,而我们的是数据源是单独定义的,也可以理解为一个小的store,并且vue3有了reactive、ref等composition api的加持,实现一个数据互通的store更简单了,所以你所担心的问题也解决了,可以在axios配置文件里,引入你定义的哪个对象就可以直接使用了
from vue3-ts-template-h5.
Related Issues (7)
- help me HOT 5
- 代码克隆后,使用npm安装node_modules启动报错
- 看到App.vue里面router-view标签直接被全部keepalive了,vue3 HOT 2
- npm run serve 报错 HOT 3
- readme.md Anchor point jump failed HOT 5
- 提个文档上看到的问题 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue3-ts-template-h5.