需求是:在方法一执行完成后再执行getchartAlarmNumber(),避免因为网络卡顿造成逻辑错误
方法一:在promise里一定要记得resolve();
init1() {
const that = this;
return new Promise((resolve, reject) => {
if (that.istowel) {
util.HttpService.doPost({
url: util.Api.URL.URL_towerAlarmSuppress,
data: {
queryStartTime: that.currentParam.alarmTimeStart,
queryEndTime: that.currentParam.alarmTimeEnd,
// userId: util.UserInfo.getUserInfo().userId,
},
success: (res) => {
if (that.isoneday) {
that.alarmSuppressNum = res.data[0].num;
resolve(res.data[0].num); //告警压制 ;
} else {
var data = res.data;
var list = [];
for (let i in data) {
list.push(data[i].num);
}
console.log('告警压制chart接口', list);
that.alarmSuppressNumList = list;
resolve(list);
}
},
fail: (err) => {
console.log(err)
}
});
} else {
let numlistdata = [];
resolve(numlistdata); //告警压制
};
});
},
方法二:在方法前要加async 修饰,
async init2() {
await that.init1();
//告警折线数量
console.log('我在init1数据获取之后执行');
that.getchartAlarmNumber();
},
调用init2
this.init2();
网友评论