官方文档:https://cli.vuejs.org/zh/config/
1.根目录新建vue.config.js文件
module.exports = {
devServer: {
open: true,
proxy: {
'/api': {
target: "http://api.jisuapi.com/",
changOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
},
}
2.设置axios baseURL
axios.defaults.baseURL = '/api';
更多
module.exports = {
//devServer.proxy适用于本地开发使用,
//生成环境请用第三方代理软件,如nginx。
devServer: {
port: 9999, //本机端口号
host: "localhost", //本机主机名
https: false, //协议
open: true, //启动服务器时自动打开浏览器访问
proxy: {
'/api': {
//目标服务器,代理访问到http://localhost:8888
target: "http://localhost:8888",
changOrigin: true, //开启代理
// ws 重写api/api
pathRewrite: {
'^/api': ''
}
}
}
},
// css全局配置
css: {
loaderOptions: {
sass: {
prependData: `@import "./src/common/css/global.scss";`
}
}
}
}