Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Nuxt中从另一个Vuex状态访问一个Vuex状态?_Javascript_Vue.js_Vuex_Nuxt.js - Fatal编程技术网

Javascript 如何在Nuxt中从另一个Vuex状态访问一个Vuex状态?

Javascript 如何在Nuxt中从另一个Vuex状态访问一个Vuex状态?,javascript,vue.js,vuex,nuxt.js,Javascript,Vue.js,Vuex,Nuxt.js,我在Nuxtstore目录中有两个Vuex存储。我无法从另一个商店访问一个商店的状态,即使是通过routstate 存储1:index.js export const state = () => ({ token: false }) export const getters = {} export const mutations = {} export const actions = {} export const state = () => ({ apiBase:

我在Nuxt
store
目录中有两个Vuex存储。我无法从另一个商店访问一个商店的状态,即使是通过
routstate

存储1:
index.js

export const state = () => ({
    token: false
})
export const getters = {}
export const mutations = {}
export const actions = {}
export const state = () => ({
    apiBase: 'https://myurl.com/'
})
export const getters = {
    getAPI: (state, rootState) => {
        // Need the state token from index.js here
    },
}
export const mutations = {}
export const actions = {}
商店2:
api.js

export const state = () => ({
    token: false
})
export const getters = {}
export const mutations = {}
export const actions = {}
export const state = () => ({
    apiBase: 'https://myurl.com/'
})
export const getters = {
    getAPI: (state, rootState) => {
        // Need the state token from index.js here
    },
}
export const mutations = {}
export const actions = {}
这里,

  • state
    返回
    api.js
    中的状态变量,即
    apiBase
  • routeState
    返回
    api.js中的getter
  • 在Vuex Getter中未定义,无法工作

如何从index.js访问状态或getter?

根状态在getter中的第三个参数中公开

const getters = {
  getApi: (state, getters, rootState) => {
    // Access the state token from index.js
    rootState.token
 }}
查看此页面了解更多详细信息