Vue突然无法进行跨域转发

 

做前后端分离的开发的时候都知道,前后端的端口不同,比如后端的端口8082,前端vue默认端口8080,。要想直接获取数据在开发阶段只能做转发,在vue.config.js中增加

module.exports = {
    runtimeCompiler: true,
    publicPath: '/', // 设置打包文件相对路径
    devServer: {
      // open: process.platform === 'darwin',
      // host: 'localhost',
      port: 8071,
      open: true, //配置自动启动浏览器
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:8082/', //对应自己的接口
          changeOrigin: true,
          ws: true,
          pathRewrite: {
            '^/api': ''
          }
        }
      }
     },
  }

,这样基本就行了,但是在vue开发的时候会有时出现无法转发的情况,比如上一次还行,在后端修改后,有个带参数的提交后,突然就不行了。提示

Proxy error: Could not proxy request /auth/google from localhost:8080 to https://localhost:8082 (DEPTH_ZERO_SELF_SIGNED_CERT).

 

查了半天,没啥结果,后来重装一下vue-cli 就好了,也许是系统的一个bug吧,也请官方改进一下

你可能感兴趣的:(vue,vue,proxy)