早上好,我遇到了这样的问题: 当我通过Vuex操作发送axios请求时,服务器看不到该会话。但是,当我直接从组件发送请求时,服务器会看到该会话,并且一切正常。可能是什么问题呢? 使用Express作为服务器中间件,并使用Express-Session作为会话。
export const actions = {
nuxtServerInit ({ dispatch, commit }, { req }) {
if (req.session && req.session.userID) {
console.log(req.session);
commit('SET_USER_AUTH', req.session.userID)
}
},
getUserInfo({ commit }) {
axios.get('/api/userInfo')
.then(response => {
console.log('all is ok');
})
.catch(error => {
axios.post('/api/killUser')
.then(response => {
})
.catch(error => {
})
})
}
}
会话对象如下(在请求中):
Session {
cookie:
{ path: '/',
_expires: 2020-02-24T09:58:31.464Z,
originalMaxAge: 2419200000,
httpOnly: true } }
但是在nuxtServerInit操作中,会话对象看起来像这样:
Session {
cookie:
{ path: '/',
_expires: 2020-02-23T18:17:12.755Z,
originalMaxAge: 2419200000,
httpOnly: true },
userID: 1 }
这是怎么了?