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)
             })
         }
  • 相关阅读:
    jQuery扩展extend一
    json对象的操作,json工具
    typeof操作符的返回值
    jacksonall的使用,解析json
    jQuery的扩展
    An Introduction to Computer Thinking
    lazy初始化和线程安全的单例模式
    Compiler Principle
    Lineare Algebra
    Mathematik
  • 原文地址:https://www.cnblogs.com/tutuj/p/14603398.html
Copyright © 2011-2022 走看看