vue-cli3 想请求多个不同域名的接口,配置是这样吗?如果到生产环境中再该如何配置呢?
我的
vue.config.js
文件是这样配置的
var webpack = require("webpack");
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里配置呢
求大佬们帮帮忙 在这有礼了 多谢各位。真不知道咋解决了