vue 2.0 配置方式:
在config目录中找到index.js
'/api': { //代理地址
target: 'http://10.1.0.34:8000/', //需要代理的地址
changeOrigin: true, //是否跨域
secure: false,
pathRewrite: {
'^/api': '/' //本身的接口地址没有 '/api' 这种通用前缀,所以要rewrite,如果本身有则去掉
}
}
vue 3.0 配置方式:
(根目录下面创建vue.config.js )此文件需要自己手动创建,记得注意pathRewrite不能忘记了
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://suggestion.baidu.com/',
ws: true,
changeOrigin: true,
pathRewrite: {'^/api' : ''}
}
}
}
}
如果需要,配置多个服务器,复制粘贴即可,记得修改/api