that.submit_order_info();
that.submit_order_info().then(res => {
console.log('啊啊啊' ,res)
that.get_check_submit_order()
})
我想等submit_order_info 这个接口调用后,再执行that.get_check_submit_order() 这个接口的调用,
请问如何去修改?
两种方法:
一种使用promise.then
const submit_order_info = () => {
return new Promise((resolve, reject) => {
...
resolve()
})
}
that.submit_order_info().then(res => {
that.get_check_submit_order()
})
还有一种用async await
const test = async () => {
let res = that.submit_order_info()
that.get_check_submit_order()
}
就如同OP你写的一样直接写在 submit_order_info
的 .then()
当中。
fn(){
that.submit_order_info().then(res => {
that.get_check_submit_order().then(res2 = >{
...
})
})
}
或者改写成 async/await
的方式。
async fn(){
...
// 如果需要返回值
const orderInfo = await that.submit_order_info()
// 如果不需要返回值
await that.submit_order_info()
const checkInfo = await that.get_check_submit_order()
...
}
使用async...await处理。
async init() {
await this.submit_order_info();
await this.get_check_submit_order();
}