React數(shù)據(jù)交互

axios

fetch語法:

    fetch('url接口地址',
        {
          配置信息
        )
    .then(res=>{
        return res.json() //將數(shù)據(jù)轉(zhuǎn)換成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跨域方案:http://www.itdecent.cn/p/95b2caf7e0da

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

fetch數(shù)據(jù)交互:https://segmentfault.com/a/1190000003810652

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom閱讀 3,214評論 0 3
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,616評論 19 139
  • # Ajax標簽(空格分隔): 筆記整理---[TOC]### 從輸入網(wǎng)址開始:- 在學(xué)習(xí)ajax之前,你應(yīng)該先了...
    V8閱讀 344評論 1 0
  • 《宮心計》由佘詩曼、楊怡、陳豪、鄭嘉穎領(lǐng)銜主演,梅小青擔(dān)任監(jiān)制。該劇主要以唐朝宮廷為背景,講述了唐朝后宮為權(quán)為情爾...
    A虎嗅薔薇閱讀 247評論 0 1
  • 01 晚十點我走出圖書館,本來邁向?qū)嬍业耐仁樟嘶貋恚赞D(zhuǎn)30度,最終選擇了夜跑的小路。 沿水泥路右邊的白線走,到路...
    須川亮閱讀 400評論 0 1

友情鏈接更多精彩內(nèi)容