zoukankan      html  css  js  c++  java
  • js数组中的每一项异步请求

    数组中的每一个选项,都进行一次异步请求,然后所有请求完成再操作返回值,Promise.all


        getInfo = (param) => {
            const { getData } = this.props // getData为接口请求
            return new Promise(resolve => {
                getData ({
                    params: {
                        param
                    }
                }).then(result => {
                    if (result.statusCode === 200){
                        resolve(result.data)
                    } else {
                        resolve({})
                    }
                }).catch(() => {
                    resolve({})
                })
            })
        }

         getArrayInfo= () => {
             const  inputList = [1,2,3,4]
             const list = []
             inputList.map(item=> {
                     const temp = this.getInfo(item)
                     list.push(temp)
             })
             Promise.all(list).then(res => {
       //res为返回的接口数据,数组形式
               console.log(res)
             })
         }
  • 相关阅读:
    RT-thread内核之事件
    RT-thread内核之互斥量
    RT-thread内核之信号量
    RT-thread内核之进程间通信
    RT-thread内核之异常与中断
    RT-thread内核之IO设备管理系统
    RT-thread内核之小内存管理算法
    RT-thread内核之系统时钟
    RT-thread内核之定时器管理
    s19文件格式详解
  • 原文地址:https://www.cnblogs.com/tutuj/p/14603398.html
Copyright © 2011-2022 走看看