Vue 2.5.x 和Vue 2.6.x 使用axios解决跨域配置写入地方的不同总结

找了好久,只找到  vue2和vue3 的配置详细  

没想到vue 2.6 就和之前不一样了

 

总结一下:vue2.5.x 需要在项目根目录下config/index.js 进行跨域配置。(src同级文件夹)

 

      


 proxyTable: {
      '/apis': {
        target: 'http://localhost:40679/', // 要解决跨域的接口的域名
        secure: false, // 如果是https接口,需要配置这个参数
        changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
        pathRewrite: {
          '^/apis': '' // 路径重写
        }
      }
    }

    vue2.6.x 需要在项目根目录下新建 vue.config.js 进行跨域配置。

devServer: {
    proxy: {
      //如需跨域请求多个域名,在此对象进行扩展即可
      "/apis": {
        target: "http://localhost:40679/",
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/apis": ""
        }
      }
    }
  }

 

     

 

posted @ 2022-05-09 20:54  耗油炒生菜  阅读(405)  评论(0)    收藏  举报