方式一
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)
})