[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.html

  • 修改config/index.js(基於Vue-CLI2)
  • 增長proxyTable
module.exports = {
  dev: {
    // proxyTable: proxyConfig.proxyList, // 無效,不使用,20190422
    proxyTable: {
      '/api': {
          target: 'http://localhost:8830',//後端接口地址
          changeOrigin: true,//是否容許跨越
          pathRewrite: {
              '^/api': '/api',//重寫,
          }
      }
    },
  }
}
相關文章
相關標籤/搜索