zoukankan      html  css  js  c++  java
  • vue使用promise.all异步实现多个请求完成之后在执行某些操作

    使用场景:多个请求方法拿到数据之后需要对这不同的数据进行比较,之后在输出并渲染

    思路:使用promise.all()异步操作:

    Promise.all([
                 //上架
                 new Promise((resolve,reject)=>{
                     this.axios(config.API + '/api/aply/statistics/hit_the_shelf',{},params).then((res)=>{
                       console.log(res)
                       resolve(res)
                    })
                 }),
                 //上架环比
                 new Promise((resolve,reject)=>{
                    this.axios(config.API + '/api/aply/statistics/hit_the_shelf',{},params1).then((res)=>{
                       conso.log(res1)
                       resolve(res1)
                   })
              }),
         ]).then(res=> {
            console.log(res)                   //是一个数组,里边的res[index]值就是两个不同的请求返回的结果
    })
  • 相关阅读:
    win10使用WampServer部署magento
    JavaScript的this详解
    jQuery的css
    jQuery.cssHooks
    jQuery属性
    jQuery选择器
    ajax中的stasus错误详解
    ajax
    js数组中的注意
    js的严格模式
  • 原文地址:https://www.cnblogs.com/wd163/p/13545702.html
Copyright © 2011-2022 走看看