版权声明:本文为博主原创文章,转载时请注明出处。--如需支持,请联系QQ:342930411填写付费技术支持 https://blog.csdn.net/php521php/article/details/85371072
1.安装axios
npm install axios
2.生成本地webpack配置文件
npm run eject
3、配置package.json中
配置单个跨域
"proxy": {
"/*": {
"secure": false,//如果有https可以写true
"target": "http://api.map.baidu.com",//请求百度地图
"changeOrigin": true
}
}
配置多个跨域
"proxy": {
"/v1": {
"secure": false,
"target": "http://api.map.baidu.com",
"changeOrigin": true
},
"/mqiot": {
"secure": false,
"target": "https://api.pythoniot.cn",
"changeOrigin": true
}
}
实际请求地址是:/v2/movie/、/mqiot/?type=device&id=
至此,React跨域配置完成