链式调用(一个方法里调用多个接口 getUserInfo、getIfVote接口名称)
注:如果一个接口的参数需要再上一个接口中获取 可以使用上述方法 也可以用下边的方法
方法一 :
getUserInfoData() {
getUserInfo({})
.then((res) => {
console.log(res);
if (res.status == 200) {
console.log(res, "============>>>1");
_this.userInfo = res.data.data ? res.data.data : {};
}
return getIfVote({ userId: res.data.data.id });
})
.then((res) => {
if (res.status == 200) {
console.log(res, "=================2");
if (res.data == false) {
_this.isShow = true;
} else {
_this.isFalse = true;
}
}
});
}
方法二:
getUserInfoData() {
getUserInfo({}).then((res) => {
console.log(res);
if (res.status == 200) {
console.log(res, "============>>>1");
_this.userInfo = res.data.data ? res.data.data : {};
_this.getIfVoteData(_this.userInfo.id);
}
});
},
getIfVoteData(userId) {
getIfVote({ userId }).then((res) => {
if (res.status == 200) {
console.log(res, "=================2");
if (res.data == false) {
_this.isShow = true;
_this.getDataList();
} else {
_this.isFalse = true;
_this.getVoteStatisticsNumber(userId);
}
}
});
},