【发布时间】:2020-10-26 13:43:34
【问题描述】:
我在 Nuxt store 目录中有两个 Vuex 存储。即使通过routeState,我也无法从另一家商店访问一家商店的状态。
商店1:index.js
export const state = () => ({
token: false
})
export const getters = {}
export const mutations = {}
export const actions = {}
商店 2:api.js
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 -
this在 Vuex getter 中未定义,它不起作用
如何从 index.js 访问 state 或 getter?
【问题讨论】:
标签: javascript vue.js vuex nuxt.js