何时需要采用异步编程:在使用多个数据请求时

如果存在一个接口需要另一个接口的返回的数据时,需要做异步等待

async userLove(){
await user_love({uid:this.$store.state.user_id}).then((res)=>{
// console.log('喜欢列表')
// console.log(res)
//获取喜欢列表的ID数组后,转换成字符串,
var arr=[];
arr=res.data.ids;
console.log(arr)
this.$store.state.user_love_id=arr.join(",");
console.log(this.$store.state.user_love_id)
})
await music_detail({ids:this.$store.state.user_love_id}).then((res)=>{
//搜索所有歌曲的详情
console.log("-------ids的详情")
console.log(res)
//将用户喜欢的歌曲列表存入公共库
this.$store.state.user_love_list=res.data.songs;
console.log(this.$store.state.user_love_list)
})
posted @ 2022-03-03 00:59  Chiffon1996  阅读(35)  评论(0编辑  收藏  举报