背景
vue2,异步操作并行运行
需求
某个页面现时需要一些接口请求回来的枚举值作为查询条件可供选择,然后将这些查询条件作为入参,请求列表数据。这就造成了我需要先调用枚举值接口,等枚举值接口调用完了,再调查询接口。
错误示例1
如下代码,我希望等this.getMapList()里面的接口全部调用完成后,再执行 this.handleMapData()和 thi.getList()。
async mounted() {
await this.getMapList()
this.handleMapData()
this.getList()
},
methods() {
// 这两是枚举值接口
getIndustryList() {
service.queryIndustryStyleList().then(res => {
this.industryStyleList = res.result
console.log(this.industryStyleList, 'industryStyleList')
resolve()
}).catch(err => {
console.log('111', err)
this.industryStyleList = []
EMessage(err.error_info, 'error')
})
},
getInvestList() {
service.