Vuex提交在axios内部不起作用,然后阻止。 当我尝试在axios获取请求后提交时,它不起作用。该get请求之所以有效,是因为..如果我尝试记录响应,它将记录在我的终端中。
export const state = () => ({
user : {}
})
export const mutations = {
set_user: (state, data) => state.user = data
}
export const actions = {
initAuth(vuexContext, token){
if( token ){
/**
* This commit working
*/
vuexContext.commit('set_user', {name: 'sunny'})
/**
* But if I want to commit after this get request, it not working,
* But consoling correct response
*/
this.$axios.$get('/me')
.then(res => {
vuexContext.commit('set_user', res)
console.log(res)
})
.catch(err => console.log(err.response))
}
}
}