vue配置跨域

在config->index.js中

添加跨域地址

'/api': {
        target: 'http://192.168.6.202:8803',//设置你调用的接口域名和端口号 别忘了加http
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'//用'/api'代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
        }
      },

如图:

在组件中用axios 访问

 

posted @ 2018-05-03 18:10  赛赛大人  阅读(171)  评论(0)    收藏  举报