1.首先,项目根目录新建vue.config.js文件
2.其次,配置如下代码:
module.exports = {
devServer: {
open: true,
port: port,
host: '0.0.0.0',
https: false,
proxy: {
'/api': { //用/api代替服务端真实地址
target: `http://localhost:8888`, //服务端真实地址
changeOrigin: true, //运行跨域
pathRewrite: {
'^/api': '' //请求的时候,地址重写
}
}
}
}