等待多个请求(请求并发执行)都完成后结束Loading框
onMounted(() => initializeApp(
initSwiper(),
initNoticeText(),
initCardTypes(),
initCards()
));
export const initializeApp = async (...promises: Promise<void>[]) => {
showLoading();
try {
await Promise.all(promises);
} catch (e) {
console.error(e);
} finally {
hideLoading();
}
};
const initCards = async () => {
return getCards().then(res => {
cards.value = res.rows as card[]
})
}
export const getCards = () => {
return httpPostByForm<any, card>("xxxx, {
clientType,
hot: "true",
});
};
export const httpPostByForm = <T, U>(url: string, data?: any) => {
return http<T, U>({
method: "POST",
url: url,
header: { "Content-Type": "application/x-www-form-urlencoded" },
data: data,
});
};
export const http = <T, U>(options: UniApp.RequestOptions) => {
return new Promise<HttpResponse<T, U>>((resolve, reject) => {
uni.request({
...options,
success(res) {
resolve(res.data)
},
false(err: any) {
reject(err);
},
});
});
};