vue-cli3(cli3 文件中没有vue.config.js ,进行额外的配置)
本地项目调后台接口,会跨域,为了解决这个问题 进行代理配置
需要新建vue.config.js
vue.config.js 中
devServer: {
disableHostCheck: true,
proxy: { //匹配规则
‘/api‘: {
//要访问的跨域的域名
target: ‘http://172.16.8.51:8083‘,
ws: true,
secure:false, // 使用的是http协议则设置为false,https协议则设置为true
changOrigin: true, //开启代理
pathRewrite: {
‘^/api‘: ‘‘
}
}
}
}
调用 /api 就会自动匹配到 http://172.16.8.51:8083
const url = ‘/api/login‘; post(url)
原文:https://www.cnblogs.com/GoTing/p/14719443.html