mounted() {
this.getData()
},
methods:{
// async 定义一个异步函数 getData()
// await 同步执行函数1,函数2
async getData(){
let data = this.axios.post('1').then(res=>{
if(res.code == 200){
console.log(res)
return res.data.id;//返回id,供下个接口使用
}
})
await this.axios.post('2',{
id:data
}).then(res=>{
if(res.code == 200){
console.log(res)
return res.data.id;//返回id
}
})
},
}
async、await简单使用
最新推荐文章于 2024-04-22 16:23:27 发布