【发布时间】:2021-04-22 17:03:42
【问题描述】:
如何从我的store 文件夹中的一个文件访问我的store 文件夹中的另一个文件中存在的突变?
这是我的目录:
store/
user.js
loading.js
在user.js 我有:
async googleSignInRedirect({ commit }) {
try {
const result = await this.$fire.auth.getRedirectResult()
if (result.credential) {
// const credential = result.credential
// console.log('got a credential? ', credential)
this.$router.replace('/')
commit('loading/SET_LOADING', false) //< -- what is correct way to write this ?
}
return null
} catch (error) {
console.error(error)
}
},
这里是loading.js 代码:
export const state = () => ({
loading: false
})
export const mutations = {
SET_LOADING(state, payload) {
state.loading = payload
}
}
如何从user.js 访问loading.js?如果我执行上述样式,我会在控制台中收到以下错误:
vuex.esm.js?2f62:791 [vuex] unknown local mutation type: loading/SET_LOADING, global type: user/loading/SET_LOADING
【问题讨论】:
标签: vuex vuex-modules