创建一个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: 'http://admintest.happymmall.com/manage/', // 线上后端地址
changeOrigin: true, //允许跨域
pathRewrite: {
'^/api': ''
}
}
}
}
}
在地址中加上"/api/地址" 获取地址 解决跨域 如: