vue 使用 axios 设置请求带上cookie

axios 默认请求是不会带上cookie的,所以需要自己设置

方法一:全局设置:

在 main.js 入口文件配置

import axios from 'axios'

// 全局设置 axios 发送请求带上cookie
axios.defaults.withCredentials = true

方法二:使用时设置:

login(){  //登录方法 由子组件回调
        var params = {
          account: this.account,
          password: this.password
        }
        this.$http.post(
                "/api/admin/login",
                this.$qs.stringify(params),
                {withCredentials: true})   //调用时设置 请求带上cookie
        .then(function (response) {
          console.log(response)
        })
        .catch(function (error) {
          console.log(error)
        })
      }
发布了98 篇原创文章 · 获赞 26 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/weixin_42425970/article/details/104082540