vuex

63 阅读1分钟

关于子模块访问父模块中的state的问题

image.png

user.js需要使用index.js中的state里的 backBaseUrl: "http://127.0.0.1:8000/"

actions部分传递的参数context内就有rootState

actions:{
    // 获取信息
    getinfo(context, data){
        axios({
            headers: {
            },
            method: "GET",
            url: context.rootState.backBaseUrl + "user/info/",
        }).then((resp)=>{
        });
      },
}

可以通过这个rootState来使用父模块index.js中的state变量