10224°

[Vue.js]跨域访问四种解决方法

报错: has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

  • 修改config/index.js(基于Vue-CLI2)
  • 增加proxyTable
module.exports = {
  dev: {
    // proxyTable: proxyConfig.proxyList, // 无效,不使用,20190422
    proxyTable: {
      '/api': {
          target: 'http://localhost:8830',//后端接口地址
          changeOrigin: true,//是否允许跨越
          pathRewrite: {
              '^/api': '/api',//重写,
          }
      }
    },
  }
}

本文由【Danni3】发布于开源中国,原文链接:https://my.oschina.net/u/2464371/blog/3040815

全部评论: 0

    我有话说: