【问题标题】:how to set session in front(nuxtjs)?如何在前面设置会话(nuxtjs)?
【发布时间】: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


【解决方案1】:

req是服务端的,所以你不会在客户端得到它,如this page所示,这只是服务端的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-25
    • 2014-11-09
    • 2023-03-08
    • 2019-06-27
    • 1970-01-01
    • 2012-02-23
    • 2014-01-03
    • 2017-01-15
    相关资源
    最近更新 更多