vue/cli 4 配置多个代理服务器
2021-11-17 本文已影响0人
很好就这样吧
vue.config.js
module.exports = {
publicPath: '/',
outputDir: 'dist',
assetsDir: 'static',
filenameHashing: true,
devServer: {
open: true, // 自动打开浏览器
host: '127.0.0.1',
port: 8081,
https: false,
hotOnly: false,
disableHostCheck: true,
proxy: {
"/api": {
target: 'http://xxxxxxx', // 这个地址结尾我原本加了一个‘/’,然后一直报404,去掉就好了
changeOrigin: true,
pathRewrite: {
'^/api': '/'
}
},
'/bpi': {
target: "http://xxxxxx",
changeOrigin: true,
pathRewrite: {
'^/bpi': '/'
}
},
'/cpi': {
target: 'http://',
changeOrigin: true,
pathRewrite: {
'^/cpi': '/'
}
}
},
before: app => {
}
},
// 构建时开启多进程处理 babel 编译
parallel: require('os').cpus().length > 1,
// https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
pwa: {},
// 第三方插件配置
pluginOptions: {}
};
在main.js里面,设置baseURL
axios.defaults.baseURL = ''