【发布时间】:2022-01-20 04:52:11
【问题描述】:
我有代码来设置在邮递员中工作的会话
首先:设置我的会话并且它可以工作
const user = {
name: 'afshin',
};
req.session.user = user
res.status(200).send({data:req.session.user,status:200});
第二次:检索会话
console.log(req.session.user)
当我向邮递员提出请求时,这有效。但是当我在客户端(nuxt + axios)上使用时它不起作用
第三:在前端
this.$axios
.post(
'http://localhost:7000/auth/session-result',
{ data: 'salam' },
{
headers: { 'Content-Type': 'application/json' },
},
{ withCredentials: true },
)
.then((res) => {
console.log(res)
})
.catch((error) => {
console.log(error)
this.setState({
errorMessage: `Server Error`,
loading: false,
})
})
我在前端做错了什么?
【问题讨论】:
-
分享正在工作的邮递员请求正文。
-
req用于服务器端,因此您不会在客户端获取它。 -
嗨,如果我的回答有帮助,请点赞。
标签: vue.js express session nuxt.js