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")})
  };

  

 

 

 

posted @ 2022-01-18 16:03  郭杰前端开发  阅读(210)  评论(0编辑  收藏  举报
## 希望内容对你有帮助,如果有错误请联系我 q: 1911509826,感谢支持