美文网首页
react数据请求,跨域

react数据请求,跨域

作者: 夏夏夏夏顿天 | 来源:发表于2018-09-26 11:16 被阅读2次

可以用jQuery的ajax,但是就单单引入了,太重了,所以推荐使用 axios,fetch

跨域解决

create-react-app

// package.json
// .........
"proxy": "填上你需要跨域的域名"  //   "proxy": "https://api.readhub.cn"

跨多个域

//package.json中加入
//some scripts
,
  "proxy": {
    "/api/RoomApi": {
      "target": "http://open.douyucdn.cn",
      "changeOrigin":true
    },
    "/api/v1":{
      "target":"http://capi.douyucdn.cn",
      "changeOrigin":true
    }
  }

参考:https://segmentfault.com/q/1010000012094380

相关文章

网友评论

      本文标题:react数据请求,跨域

      本文链接:https://www.haomeiwen.com/subject/biywnftx.html