nginx + react + 接口跨域处理
1. nginx中加入json文件
2. 启动nginx : start nginx 访问 127.0.0.1/login.json 确定数据可以正常访问
3. React中使用fetch调用接口
fetch('http://127.0.0.1:8001/login.json',{ headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', }, }) .then(response=>response.json()) .then(data=>console.log(data)) .catch(e=>{console.log("error")}) };
## 希望内容对你有帮助,如果有错误请联系我 q: 1911509826,感谢支持