首先在根目录下创建一个vue.config.js文件
vue.config.js:
module.exports = {
devServer: {
host: "localhost",
port: 8080, // 端口号
https: false, // https:{type:Boolean}
open: true, //配置自动启动浏览器
// proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
// 配置多个代理
proxy: { //配置跨域
'/api': {
target: 'http://m.kugou.com/', //这里后台的地址模拟的;应该填写你们真实的后台接口
changOrigin: true, //允许跨域
pathRewrite: {
/* 重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时
实际上访问的地址是:http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api
*/
'^/api': ''
}
},
}
}
};
这里注意一下,因为我写的的仿酷狗的移动端项目,所以用的target是http://m.kugou.com/,如果你们是写的其他项目,请记得自行修改
接着记得把你们下述地方改成 /api,为