Git Product home page Git Product logo

Comments (1)

weizhanzhan avatar weizhanzhan commented on June 19, 2024

都说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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.