// 初始化 async init() { let res=await this.getAreaList(); // 处理返回结果 if(res.data){ this.arrAreaList=res.data.provinceList; } let res1=await this.getUserAddress('900003354'); // 处理返回结果 if(res1.data){ let cityId = res1.data.discover.cityId+'';; this.getCityName(cityId); } await this.getSingerList(); }, // 获取地址列表 getAreaList(userId,callBack,cityId){ return axios.get(baseURL + 'cms/api/fetch.do?cmd=discoverService|selectProvince&req={}') }, // 获取用户地址信息 getUserAddress(userId){ if(!userId) return; let req=encodeURIComponent(`{"query":{"userId":${userId}}}`); return axios.get(baseURL + 'cms/api/fetch.do?cmd=discoverService|selectuserCityId&req='+req) }, // 获取地址名称 getCityName(cityId){ if(cityId==0){ this.curProvinceName='火星'; this.curProvinceID=cityId; } else { this.curProvinceName='北京'; this.curProvinceID=1202; this.arrAreaList.some(function(item) { if (cityId.substring(0, 4) ==item.provinceID) { this.curProvinceName=item.provinceName; this.curProvinceID=cityId.substring(0, 4); return true; } }, this); } console.log(4444) }, // 获取歌手列表 getSingerList(){ console.log(33333333) var req=encodeURIComponent(`{"query":{"gender":"${this.curGender}","provinceID":${this.curProvinceID}},"page":{"pageSize":20,"pageNo":${this.curPage}}}`); axios.get(baseURL + 'cms/api/fetch.do?cmd=discoverService|selectProvincePage&req='+req, { emulateJSON: true }).then((res)=> { console.log(res); },(err)=> { console.log(err); }); },
vue中使用 async & await
猜你喜欢
转载自www.cnblogs.com/yuesu/p/9593415.html
今日推荐
周排行