方式一
getData: async function() { // 同步方法
  try { // 顺序请求
    await this.getSetupList();
    await this.getRoleList();
    await this.getList();
  } catch (e) {}
}
方式二
const getData1 = function(code) { // 定义方法
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(11)
            resolve(true)
        }, 1000)
    })
}
const getData2 = function(code) { // 定义方法
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(22)
            resolve(true)
        }, 1000)
    })
}
const getData3 = function(code) { // 定义方法
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log(33)
            resolve(true)
        }, 1000)
    })
}

getData1().then(() => {
    return getData2()
}).then(() => {
    return getData3()
}).then(() => {
    console.log('结束')
})

// 并发
Promise.all([
    getData1(),
    getData2()
  ]).then(result => {
    console.log(result)
  })
Logo

前往低代码交流专区

更多推荐