es6 Promise.all工作中用法,调用完一个接口后就调用另一个接口

nodeClick() {
      this.$http
        .post().then(res => {
          if (res.data.success) {
            if (res.data.data.datas.length !== 0) {
              var arrs = []
              for (let item of res.data.data.datas) {
                arrs.push(this.timeClick(item.id))
              }
              Promise.all(arrs).then(response => {
                console.log(response) //两个接口中的共同数据
              })
            } else {
              self.$message({ type: 'warning', message: '暂无数据' })
            }
          }
        })
        .catch(function(error) {
          self.$message({ type: 'info', message: '系统错误!' })
        })
},
timeClick(val) {
      return this.$http.post(url,{传给后端的参数})
}

猜你喜欢

转载自blog.csdn.net/weixin_43173924/article/details/89841867