//new一个promise对象并在里面执行第一个异步方法
var promise = new Promise(function(resolve,reject){
axios({
method: 'post',
url: common.getApi() + '/api/doctorDept/getAllDoctorDept',
}).then(res => {
if (res.data.success) {
console.log('成功')
resolve()
}
})
})
//使用这个promise对象的.then开始执行第二个异步方法,新建一个promise并且return它
promise.then(function(){
return new Promise(function (resolve, reject) {
axios({
method: 'post',
url: common.getApi() + '/api/doctorDept/getAllDoctorDept',
}).then(res => {
if (res.data.success) {
console.log('成功2')
resolve()
}
})
})
}).then(function(){
//使用这个链式.then开始执行第三个异步方法,新建一个promise并且return它
return new Promise(function (resolve, reject) {
axios({
method: 'post',
url: common.getApi() + '/api/doctorDept/getAllDoctorDept',
}).then(res => {
if (res.data.success) {
console.log('成功3')
resolve()
}
})
})
}).then(()=>{
//使用这个链式.then,所有异步结束后执行这里的代码。
console.log('成功4');
})
promise的链式调用
最新推荐文章于 2024-08-30 14:31:36 发布