Vue proxyTable 解决开发环境的跨域问题

在 config/index.js 配置文件中,添加

dev: {
proxyTable: {
'/ssp/withdraw': {
target: 'http://dev.home.phiwifi.com', // 接口域名
changeOrigin: true, // 是否跨域
pathRewrite: {
'^/ssp/withdraw': '/ssp/withdraw' // 需要rewrite重写的
      }
}
}


具体调用方式:
var obj = {
pageSize: 20
}
this.$http.get( '/apis/health/list',{params: obj}) .then(function(res){ // 成功回调 },function(){ alert("error") })

或者
let hostName = location.host;
let protoType = location.protocol;
this.$axios({
method: "post",
url: protoType + "//" + hostName + "/ssp/withdraw/user_login",
  data: params
})

注意:修改脚手架的文件后一定要npm run dev ,重启服务后才能生效
原文地址:https://www.cnblogs.com/yzhihao/p/8385736.html