V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lightfish
V2EX  ›  问与答

axios 携带不了 cookie,是不是有什么底层的东西

  •  
  •   lightfish · 2019-05-26 17:23:38 +08:00 · 1977 次点击
    这是一个创建于 1803 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前两天试了下前后端分离的登录注册等,就像用 token 做验证,当时还是很好的运行起来了

    img

    今天也是想来试试 token 放在 header 里,但是运行的时候就出现了错误,axios 请求有携带不了 cookie,请指教。

    前端发送的请求代码如下

        import axios from "axios";
        axios.defaults.withCredentials = true;
        handleIsLogin () {
          axios({
            method: "get",
            url: "http://127.0.0.1:8000/backend/islogin"
          }).then(res=>{
            console.log(res.data);
            var response = res.data;
            this.$Modal.info({
              title: '是否登陆',
              content: response.tips
            })
          })
    
    2 条回复    2019-05-27 10:15:00 +08:00
    zuiluo
        1
    zuiluo  
       2019-05-26 17:37:45 +08:00   ❤️ 1
    语死早。。。。。如果想在 headers 里面携带 token 字段,请自己写到请求代码里了

    requestObject.headers.token = xxxxxxxxx
    hellomimi
        2
    hellomimi  
       2019-05-27 10:15:00 +08:00
    axios 请求默认是不携带 cookie 的,
    设置 axios.defaults.withCredentials=true
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2150 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:23 · PVG 18:23 · LAX 03:23 · JFK 06:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.