fecth

https://blog.csdn.net/qq_24713843/article/details/78866713

这篇文章很不错!

export function post(url,paramsObjs) {
  var result = fetch(url, {
    method: 'POST',
    mode : 'no-cors',
    // credentials: 'include',
    headers: {
      'Accept': 'application/json, text/plain, */*',
      'Content-Type': 'application/x-www-form-urlencoded'
    }, // 注意 post 时候参数的形式 body: "a=100&b=200" });
    body: obj2params(paramsObjs)
  })
  return result;
export function get(url) {
  var result = fetch(url,{
    credentials:'include',
    headers:{
      "Accept":"application/json,text/plain.*/*"
    }
  });
  return result;
}

fecth返回的数据可以用.then .catch 来处理

resultHandle(result){
    result.then(res=>{
      if(res.ok){
        return res.json()
      }else{
        console.log("当前城市:"+this.props.cityName);
        console.log("当前页码:"+this.state.page);
        return ListData;
      }
    }).then(json=>{
      const data = json.data;
      const hasMore = json.hasMore;
      this.setState({
        hasMore:hasMore,
        data:this.state.data.concat(data),
        isLoadingMore:false
      })
    }).catch(err=>{
      console.log(err.message);
    })
  }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,705评论 25 709
  • 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
    远航的移动开发历程阅读 11,270评论 12 197
  • 文/Alexia ​一个朴实,平凡,正直的农民,在他人生的前35年以土地为生,之后转做生意人,一直勤勤恳恳的工作至...
    小敏纸阅读 1,563评论 8 20
  • 本来晚上一直是我的码字时间,今天有个姑娘晚饭时间临时找我,让我帮忙看一篇文,30万字,提意见,她要大修,时间很赶。...
    Yuki_云阅读 168评论 0 0
  • 那日,仅一眼,就沦陷在你如水的眸子里 那一刻,不想去在乎什么背景 什么家庭 只想悄悄地走进你的心房,声轻步平 你是...
    鲛人10阅读 402评论 2 4