zoukankan      html  css  js  c++  java
  • Promise all的使用

    //查询订单物流
                getExpressListById(expressId,callBack){
                    //返回一个promise对象
                    return new Promise((resolve, reject)=>{
                        this.$http('get', 'getExpressListById', {expressId:expressId}).then(res => {
                            callBack(res);
                            resolve();
                        }).catch(function(err) {
                            console.log(1, err)
                            reject();
                        });
                    }); 
                },
                //查询订单退款商品
                getRefundOrderGoodsByOrderId(){
                    this.$http('get', 'getRefundOrderGoodsByOrderId', {orderId:this.orderDetailList.order.id}).then(res => {
                        // console.log(res)
                        let allTask = [];//promise数组
                        res.forEach(g=>{
                            g.mallOrderGoodsRefund.expressId && allTask.push(this.getExpressListById(g.mallOrderGoodsRefund.expressId,expressList=>{g.expressList = expressList}))
                        });
                        console.log(allTask);
                        //Promise.all 执行allTask数组里的所有promise对象
                        Promise.all(allTask).then(()=>{
                            this.$forceUpdate()
                        });
                        this.refundOrderGoods = res;
                        console.log(this.refundOrderGoods,66)
                    }).catch(function(err) {
                        console.log(1, err)
                    });
                }
  • 相关阅读:
    聪明人 & 普通人
    13种模型及方法论
    面向大规模商业系统的数据库设计和实践
    分治算法
    软件架构
    隐含前提思维模型
    Git回滚代码到某个commit
    使用arthas排查 test 问题
    Arthas
    docker 操作入门
  • 原文地址:https://www.cnblogs.com/web-aqin/p/15668166.html
Copyright © 2011-2022 走看看