背景:
B请求要用到A请求的返回的数据,要求A请求先执行,B请求后执行
解决:
(1)示例一
created() {
Promise.all(
[this.getBondListData(), this.getBasicConditionsData(), this.getReleaseInformationData()]
).then((result) => {
this.getPaymentInformationData();
this.getCapitalConditionData();
this.getCreditEvaluationData();
}
).catch((error) => {
this.getPaymentInformationData();
this.getCapitalConditionData();
this.getCreditEvaluationData();
}
)
}
(2)示例二
mounted() {
this.start();
},
methods:{
async start() {
if (this.permission() == true) {
...
let code = await this.shift();
await this.requestData(code);
} else {
...
}
},
//先执行
shift() {
return new Promise((resolve, reject) => {
EMAjax.get({
url: '...',
data: this.data,
success: (data) => {
if (data && data.list && data.list.length) {
resolve(data.list[0].code);
} else {
resolve("");
}
},
error: (err) => {
resolve("");
},
});
});
},
//后执行
requestData(code) {
...
}
}