当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue proxyTable 接口跨域请求调试的示例

vue proxyTable 接口跨域请求调试的示例

2017年12月12日  | 移动技术网IT编程  | 我要评论

八月未央txt下载,睡美宁,3d太湖钓叟字谜汇总

在不同域之间访问是比较常见,在本地调试访问远程服务器。。。。这就是有域问题。

vue解决通过proxytable:

在 config/index.js 配置文件中

 dev: {
  env: require('./dev.env'),
  port: 8080,
  autoopenbrowser: true,
  assetssubdirectory: 'static',
  assetspublicpath: '/',
  //proxytable: {},
  proxytable: proxyconfig.proxylist,
  // css sourcemaps off by default because relative paths are "buggy"
  // with this option, according to the css-loader readme
  // (https://github.com/webpack/css-loader#sourcemaps)
  // in our experience, they generally work as expected,
  // just be aware of this issue when enabling this option.
  csssourcemap: false
 }

划红线部分就是设置代理参数:

在config目录创建,proxyconfig.js 写入

module.exports = {
 proxylist: {
    '/apis': {
      // 测试环境
      target: 'https://goods.footer.com', // 接口域名
      changeorigin: true, //是否跨域
      pathrewrite: {
        '^/apis': ''  //需要rewrite重写的,
      }       
    }
 }
}

在 config/index.js 配置文件上边引入

var proxyconfig = require('./proxyconfig')

使用:

服务器提供接口:https://goods.footer.com/health/list

vue请求

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网