Javascript 如何在Nuxt中从另一个Vuex状态访问一个Vuex状态?
我在NuxtJavascript 如何在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:
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
}}
查看此页面了解更多详细信息