使用Promise返回后端数据

downloadExtra(storeCode){ 
                return new Promise(resolve => {
                    webServices.post('/data',{code:code}).then(res=>{
                        resolve(res);
                    })
                })
                
            },

async download(){for(let key in this.storeCode){//遍历请求后端会进行异步请求,使用await搭配promise进行同步请求,逐个请求后端,
                   await this.downloadExtra(code).then(res=>{
                       if(res.status == '200'){
                           res就是上方代码中resolve(res)的res,即请求后端返回的值
                       }
                   });
                }
            },

 

相关文章:

  • 2021-12-28
  • 2022-01-29
  • 2022-12-23
  • 2021-07-29
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-10-29
  • 2022-12-23
  • 2021-06-08
  • 2021-11-29
相关资源
相似解决方案