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

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
地址路径请根据具体情况自行更改




转载地址

猜你喜欢

转载自www.cnblogs.com/potholing/p/9243930.html