vue-cli3中本地应用和后端接口跨域,导致axios无法携带cookie的处理

axios中api请求以/api开头,不需要配置绝对路径,如http://....之类。
在vue.config.js中配置如下:target改为你要请求的api地址

  devServer: {
    // development server port 8000
    port: 8000,
    // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
    proxy: {
      '/api': {
        target: 'http://172.16.1.110',
        ws: true,
        changeOrigin: true
      }
    }
  }

参考链接:https://cli.vuejs.org/zh/config/#devserver

你可能感兴趣的:(vue-cli3中本地应用和后端接口跨域,导致axios无法携带cookie的处理)