解决UNI-APP "请注意 showLoading 与 hideLoading 必须配对使用" 问题
https://blog.csdn.net/HRM2454/article/details/105969695
loading.js
// 加载信息,带遮罩
let needLoadingRequestCount = 0;
let loadingTimer;
export function showLoading(title = '', mask = true) {
if (needLoadingRequestCount === 0) {
uni.showLoading({
title,
mask
});
// 最长10s自动关闭
loadingTimer = setTimeout(() => {
if (needLoadingRequestCount > 0) {
uni.hideLoading();
}
}, 10000);
}
needLoadingRequestCount++;
}
// 隐藏遮罩
export function hideLoading() {
if (needLoadingRequestCount <= 0) return;
needLoadingRequestCount--;
if (needLoadingRequestCount === 0) {
loadingTimer && clearTimeout(loadingTimer);
uni.hideLoading();
}
}
使用(也可以挂在到Vue.prototype中)
-
import {
-
showLoading,
-
hideLoading
-
} from 'utils/loading'
-
-
showLoading();
-
hideLoading();