vue axios跨域请求,代理设置

在config下的index.js中的dev下的 proxyTable{}中设置代理

1 proxyTable: {
2     '/api': {
3         target: 'http://10.0.100.7:8081', //设置调用接口域名和端口号别忘了加http
4         changeOrigin: true,
5         pathRewrite:{
6           "^/api":""
7         }
8     }
9 },

接口调用时,

1 this.Axios.get('/api/resource_overview',{
2     params: {
3         vcenter_num:'vcenter1'
4     }
5 }).then(function (res) {
6     console.log(res);
7 }).catch(function (err) {
8     console.log(err);
9 })

注意:原接口:http://10.0.100.7:8081/resource_overview

   页面接口:http://localhost:8081/api/resource_overview,那个多的/api不是多余的,是声明的那个代理

posted @ 2018-07-11 17:02  秀&莹&锐  阅读(1650)  评论(0编辑  收藏  举报