Promise.all()调用接口,并处理错误

当一个页面需要一次性调用多个接口,并且这些接口都互不影响,我们可采用Promise.all()方法来调用接口,这样比之前一个一个的调用速度快些

promiseALL() {
      Promise.all(catchFun([
        this.getInformList('通知公告'),
        this.getMyApps() // 获取应用分类
      ])).then(() => {

      }).catch(() => {

      })
      function catchFun(items) {
        return items.map(item => {
          item.catch(err => {
            Promise.resolve(err)
          })
        })
      }
    },
 async getMyApps() {
      let { userId} = this
      let { data } = await getApps({userId})
      this.appClassifyList = data.data
    },

你可能感兴趣的:(javascript,vue.js,ecmascript)