React处理跨域问题

需要使用代理

在page.json中

"proxy": {
    "/api": {
      "target": "https://www.jiayiunion.com",   //你的接口地址前面的
      "pathRewrite": {
        "^/api" : ""
      },
      "changeOrigin": true
    }
  }

在这里插入图片描述
如果还是不能用或者是404报错的话就把检查一下react-scripts是哪个版本的,高版本的有时候不可以用,需要在node_module中找到react-scripts文件夹删除,
然后npm i react-scripts@1 --save-dev

引入的时候,前面加上api就行
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42697338/article/details/86572749