美文网首页
想请求多个不同域名的接口,配置是这样吗?如果到生产环境中再该如何

想请求多个不同域名的接口,配置是这样吗?如果到生产环境中再该如何

作者: 小白自学前端 | 来源:发表于2019-08-04 15:07 被阅读0次

我的 vue.config.js文件是这样配置的

module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  devServer: {
    proxy: {
      "/api": {
        target: "https://api.openbrewerydb.org"
      },
      "/api2": {
        target: "http://jsonplaceholder.typicode.com/users"
      }
    }
  },
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jquery: "jquery",
        "window.jQuery": "jquery",
        jQuery: "jquery"
      })
    ]
  },
  chainWebpack: config => {
    config.module
      .rule("vue")
      .use("vue-loader")
      .loader("vue-loader")
      .tap(options => {
        options.transformAssetUrls = {
          audio: "src"
        };
        return options;
      });
  }
};```
这个是 ```main.js``` 里axios 的配置
```axios.interceptors.response.use(
  response => {
    return response;
  },
  err => {
    console.log(err);
  }
);


axios.defaults.baseURL =  process.env.NODE_ENV === 'development' ? "/api" : ( window.location.protocol + "//" + window.location.hostname )```

这个就是部署生产环境的效果 API请求地址不对和开发环境 是不是axios里配置呢

![image.png](https://img.haomeiwen.com/i8053630/9d254b8242c76a48.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![image.png](https://img.haomeiwen.com/i8053630/710972bdf20bb7dc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

求大佬们帮帮忙 在这有礼了 多谢各位。真不知道咋解决了

相关文章

网友评论

      本文标题:想请求多个不同域名的接口,配置是这样吗?如果到生产环境中再该如何

      本文链接:https://www.haomeiwen.com/subject/flkydctx.html