1. 程式人生 > >Vue前端服務代理實現跨域請求資料。

Vue前端服務代理實現跨域請求資料。

開發中請求真實伺服器資料,配置伺服器代理實現跨域。

vue-cli + webpack 構建的專案

再 ./config/index.js 檔案中配置

proxyTable: {
      '/api':{
        target: 'http://請求的伺服器地址',
        changeOrigin: true, //是否允許跨域
        pathRewrite:{
          '^/api': ''
        }
      }
    }

然後就可以跨域請求到需要測試的真實資料