码迷,mamicode.com
首页 > 其他好文 > 详细

iview-cli 设置跨域代理服务器

时间:2018-06-29 16:27:46      阅读:938      评论:0      收藏:0      [点我收藏+]

标签:geo   history   secure   http   conf   路径   localhost   hang   fallback   

1.打开 webpack.dev.config.js

 

2.//设置跨域代理

devServer: {
  historyApiFallback: true,
  hot: true,
  inline: true,
  stats: { colors: true },
  proxy: {
    //匹配代理的url  
    ‘/api‘: {
      // 目标服务器地址
      target: localhost:8080‘,
      //路径重写
      pathRewrite: {‘^/api‘ : ‘/api‘},
      changeOrigin: true,
      secure: false
    }
  }
}

设置之后重新打开项目;

 

3.使用

//请求方法,根据实际情况使用
axios.get(‘/api/user‘).then((res) => {
     //res 为成功回调的响应
    console.log(res);
});
地址路径请根据具体情况自行更改




转载地址
 http://www.cnblogs.com/mark7/p/7722621.html#4001041

 

iview-cli 设置跨域代理服务器

标签:geo   history   secure   http   conf   路径   localhost   hang   fallback   

原文地址:https://www.cnblogs.com/potholing/p/9243930.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!