1 在根目录下创建 vue.config.js文件
2 在vue.config.js文件里面配置以下代码
/*
* @Description: 配置文件
* @Author: hai-27
* @Date: 2020-02-07 16:23:00
* @LastEditors: hai-27
* @LastEditTime: 2021-03-03 22:32:57
*/
module.exports = {
lintOnSave: false,
publicPath: './',
devServer: {
open: true,
proxy: {
'/api': {
// target: 'http://localhost:3000/', // 本地后端地址
target: '接口的基准路径', // 线上后端地址
changeOrigin: true, //允许跨域
pathRewrite: {
'^/api': ''
}
}
}
}
}
3 在每次使用接口路径的时候在前边加上/api/ 就可以使用了