美文网首页
react数据交互

react数据交互

作者: Abby_qi | 来源:发表于2018-07-05 21:27 被阅读0次

ch('url接口地址',
{
配置信息
)
.then(res=>{
return res.json() //将数据转换成promise可返回的json
})
.then(result=>{
console.log('result',result)
this.state.goods = result.goods
})
.catch(error=>{ //报错时走catch
console.log(error)
})

例如:
fetch('./api/goods.json',
{
credentials: 'include',
method: 'get',
body: JSON.stringify({ user: 'lisposter', pwd: 'souche.com'}
)
.then(res=>{
return res.json()
})
.then(result=>{
console.log('result',result)
this.state.goods = result.goods
})
.catch(error=>{
console.log(error)
})

react跨域:

前端跨域:jsonp,代理

react跨域方案:在package.json中添加

  "proxy": {
    "/v2": {
      "target": "https://api.douban.com",
      "changeOrigin":true
    }
  }

vue跨域方案:https://www.jianshu.com/p/95b2caf7e0da

后端跨域:cors,后端代理(例如:反向代理 nginx)

fetch数据交互:https://segmentfault.com/a/1190000003810652

相关文章

  • react 数据交互

    原生 - fetch :返回promise对象 语法:fetch(url+数据,{配置}).then(成功函数(...

  • React数据交互

  • React数据交互

    axios fetch语法: 例如:fetch('./api/goods.json',{credentials: ...

  • react 数据交互

    axios fetch语法: react跨域: vue跨域方案:https://www.jianshu.com/p...

  • react数据交互

    ch('url接口地址',{配置信息).then(res=>{return res.json() //将数据转换成...

  • 学习笔记——React Ref

    由于React的单向数据流设计,所以典型的 React 数据流中, 属性(props)是父组件与子组件交互的唯一方...

  • React第五天 (偷懒了一天)

    React与后台数据交互 axios: fetch: 传统 Ajax 已死,Fetch 永生:https://se...

  • Redux——React 组件中的数据传输

    React中的数据有两种:prop和state。其中prop负责对外的数据交互,state负责内部的数据管理。 R...

  • React-Native 开发笔记

    React-Native 数据库读取问题 问题描述: 原生与RN在数据库交互方面,RN端始终读取不到数据库 产生原...

  • React框架简述

    React 1.React简介 前端UI开发框架,传统的开发方式在解决服务器和用户输入的交互数据,动态反应到复杂界...

网友评论

      本文标题:react数据交互

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