vue项目开发之proxyTable 解决开发环境的跨域
2017-06-09 17:32
951 查看
在实际项目开发过程中vue cli自带的服务器,但是我们实际要去请求我们的数据接口,服务器与服务器之间产生了一个代理跨域问题,我们需要修改自带服务的配置。在config 中的index文件中,有一个proxyTable参数参数修改如下:proxyTable: { '/list': { target: 'http://xxx.xxx.com/xxx/6', pathRewrite: { '^/list': '/' } }},如果需要跨域那么需要加上参数changeOrigin:trueproxyTable: { '/list': { target: 'http://xxx.xxx.com/xxx/6',changeOrigin:true, pathRewrite: { '^/list': '/' } }},请求过程就需要这样写//账号登陆提交
submitForm:function (formName) { var info={ user_phone: this.info.username, user_pwd: this.info.password, verify_code: this.info.password } var that=this; this.$http.post('/list/login',info).then(function (res) { console.log(res.data) if(res.data.code==2000){ this.$router.push({ path: 'OrderTracking'}) }else (res.data.code==4000){ alert("登陆失败") }
}) }
项目上线时后台配置
#商家管理员端server { listen 80;server_name xxxx.xxxx.xxxx.com;#社区端location /list/ {proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection "";proxy_pass https://api.xxxx.xxx.com/seller/; }location /ui/ {proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection "";proxy_pass https://api.xxxx.xxx.com/public/; }location / {root /www/xxx/xxx;index index.html index.htm;} }
相关文章推荐
- Vue proxyTable 开发环境下前端和后端真实数据对接问题和解决跨域
- 详解vue项目和普通项目如何解决开发环境与生产环境下的跨域问题
- Webpack之proxyTable 解决开发环境的跨域问题
- 详解vue-cli开发环境跨域问题解决方案
- Vue-cli proxyTable 解决开发环境的跨域问题(转)
- Vue-cli proxyTable 解决开发环境的跨域问题
- vue-cli项目开发/生产环境代理实现跨域请求+webpack配置开发/生产环境的接口地址
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue---vue-cli 中的proxyTable解决开发环境中的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题详解
- Vue-cli proxyTable 解决开发环境的跨域问题
- vue-cli开发环境跨域问题解决方案
- 使用vue-cli+axios构建的项目本地环境API代理设置和解决跨域
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题
- Vue-cli proxyTable 解决开发环境的跨域问题