lightfish
V2EX  ›  问与答

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

  •  
  •   lightfish · May 26, 2019 · 2419 views
    This topic created in 2566 days ago, the information mentioned may be changed or developed.

    前两天试了下前后端分离的登录注册等,就像用 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 replies    2019-05-27 10:15:00 +08:00
    zuiluo
        1
    zuiluo  
       May 26, 2019   ❤️ 1
    语死早。。。。。如果想在 headers 里面携带 token 字段,请自己写到请求代码里了

    requestObject.headers.token = xxxxxxxxx
    hellomimi
        2
    hellomimi  
       May 27, 2019
    axios 请求默认是不携带 cookie 的,
    设置 axios.defaults.withCredentials=true
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1306 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 23:49 · PVG 07:49 · LAX 16:49 · JFK 19:49
    ♥ Do have faith in what you're doing.