美文网首页
Vue配置跨源携带cookies

Vue配置跨源携带cookies

作者: 王二麻子88 | 来源:发表于2020-10-20 16:03 被阅读0次

Vue配置跨源携带cookies

在开发环境中, 有时需要同源携带cookie

在 axios 中配置

import axios from "axios";
service = axios.create({
    baseURL: "/", // api的base_url
    timeout: 50000 // 请求超时时间
});
service.defaults.withCredentials = true;

export default service;

在 vue.config.js(没有在项目根目录中新建一个)中配置

module.exports = {
    devServer: {
    proxy: {
        '/wbr': {
        target: 'http://192.168.5.2/',  // 指向的后台接口地址
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '/wbr': ''
        }
      },
    }
  },
}

应用:

window.$common.baseUrl = "/ljy";

import service from "../service";

service({
    url: `${window.$common.baseUrl}/getWebSizeImageList`,
    method: "POST"
}).then((res)=>{
    console.log(res.data);
})

相关文章

网友评论

      本文标题:Vue配置跨源携带cookies

      本文链接:https://www.haomeiwen.com/subject/skpdmktx.html