vue proxyTable 接口跨域请求调试的示例
2017-09-12 09:26
771 查看
在不同域之间访问是比较常见,在本地调试访问远程服务器。。。。这就是有域问题。
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") })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- vue proxyTable 接口跨域请求调试(代理)
- vue proxyTable 接口跨域请求调试(五)
- vue proxyTable 接口跨域请求问题处理
- VUE系列三:实现跨域请求(fetch/axios/proxytable)
- vue项目开发之proxyTable 解决开发环境的跨域
- vue-cli项目开发/生产环境代理实现跨域请求+webpack配置开发/生产环境的接口地址
- Vue proxyTable 开发环境下前端和后端真实数据对接问题和解决跨域
- webpack+vuex+axios 跨域请求数据的示例代码
- Vue-resource实现ajax请求和跨域请求示例
- vue-resource 跨域 post请求 示例
- vue-cli 前端开发,后台接口跨域代理调试问题
- 使用$.getJSON实现跨域ajax请求示例代码
- 梦网云通讯查询余额API接口get_balance说明POST请求示例
- javascript跨域请求包装函数与用法示例
- 关于vue2.x使用axios以及http-proxy-middleware代理处理跨域的问题
- Vue1.0接口请求之vue-resource全攻略
- Vue2.0 vue-source jsonp 跨域请求
- vue.js实现请求数据的方法示例
- jsonp跨域请求远程接口时时出现SyntaxError: expected expression, got '<' 错误
- 《GOF设计模式》—代理(PROXY)—Delphi源码示例:代理接口