首页 > 其他 > 详细

vue-cli跨域代理配置

时间:2018-04-03 14:16:11      阅读:233      评论:0      收藏:0      [点我收藏+]
参考了好多网上文章 配置代理总是不生效 ,其实不是配置的问题 是在调用的时候出的问题 把完整的调用过程整理下来希望可以帮助其他有疑惑的小伙伴 例如 服务地址是 http://192.168.0.125/test/login 的调用过程 1 找到config ->index.js文件 配置proxyTable参数 proxyTable: { ‘/api‘: { target: ‘http://192.168.0.125/test‘, changeOrigin: true, pathRewrite: { ‘^/api‘: ‘/‘ } } /api 代替的是 ‘ http://192.168.0.125/test‘ 2 工具 封装 const service = axios.create({ timeout: 1000 * 30, withCredentials: true, baseURL:‘/api/‘, headers: { ‘Content-Type‘: ‘application/json; charset=utf-8‘ } }) 3 action调用 // 登录 export function login (params) { return request({ url:‘login‘, method: ‘post‘, data: requestParam(params) }) }

vue-cli跨域代理配置

原文:http://blog.51cto.com/8707838/2094178

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!