zoukankan      html  css  js  c++  java
  • react native 之异步请求

    第一章 异步请求  fetch的运用

    在react native  中异步请求一般用fetch这个方法, fetch的格式如下:

    const params ={
        "charset":"utf-8","sessionToken":"dedbde5567e444a2b71b36ba7af9d7c5",
        "sessionRandom":"","requestNo":"99999991470815595421","channelCode":"001",
        "clientId":"9999999","transCode":"99002",
        "requestBodyJson":"{"mobile":"13311223322","password":"000000","deviceNo":"1470815595420##","requestType":"0"}",
        "mobile":"13311223322","empNo":"","devicesn":"1470815595421","url":"/access/doSubmit.do"
    
    }
    
    
    
    
    function login(username, password, success, failure) {
    
        fetch('http://bxxsit.cpic.com.cn/sxtbweb/service/access/doSubmit.do',{
            method :'POST',
            headers:{
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body:JSON.stringify(params)
        })
            .then((response) =>response.json())
            .then((responseJson) => {
              alert(JSON.stringify(responseJson))
              AsyncStorage.setItem('message',JSON.stringify(responseJson),()=>{
            // AsyncStorage.mergeItem('person',JSON.stringify(getState()),() =>{
            //});
               })
                 })
          .catch((error) => {
                alert ("Failed")
          });
    
    
    }

    注意参数的写法与回调函数的写法.

    第二章 异步请求的优化

  • 相关阅读:
    一轮项目冲刺9
    一轮项目冲刺8
    一轮项目冲刺7
    一轮项目冲刺6
    一轮项目冲刺5
    一轮项目冲刺4
    一轮项目冲刺3
    一轮项目冲刺2
    一轮项目冲刺1
    移山小分队---每日记录01
  • 原文地址:https://www.cnblogs.com/leyan/p/5765905.html
Copyright © 2011-2022 走看看