uni-app的loading在安卓设备上不会消失
uni-app的loading在安卓设备上不会消失
产品分类
- uniapp/H5
PC开发环境操作系统
- Windows
PC开发环境操作系统版本号
- 11
HBuilderX类型
- 正式
HBuilderX版本号
- 3.4.6
浏览器平台
- Chrome
浏览器版本
- 100.0.4896.88
项目创建方式
- HBuilderX
示例代码
let pages = getCurrentPages();
let beforePage = pages[pages.length - 2];
beforePage.$vm.listQuery = Object.assign(beforePage.$vm.listQuery, this.listQuery);
if(beforePage.$vm.listQuery.startTime){
beforePage.$vm.listQuery.sendTime=""
}
beforePage.$vm.tabCurrent = beforePage.$vm.tabList.findIndex(item => item.value == beforePage.$vm.listQuery.contractStatus);
uni.navigateBack({
delta: 1,
success: function() {
beforePage.$vm.refresh();
}
});
操作步骤
- 点击确认筛选返回上一个页面列表刷新。
预期结果
- 预取页面展示loading,重新加载数据,加载完毕然后消除
实际结果
- 实际页面展示loading,重新加载数据,加载完毕然后未消除
bug描述
前置条件
- 路由前置拦截,调用uni-showloading,展示loading,路由响应拦截调用uni-hideloading,取消loadinng效果。
bug场景
- 在列表页点击跳转筛选页面。在筛选页面点击确认,返回列表页,调用刷新方法,重新获取列表数据,列表请求完成后,loading没有消除,在pc端和ios端的浏览器上不会出现问题,在安卓上会偶先loading不会消除。
点击确认返回上一步的代码
let pages = getCurrentPages();
let beforePage = pages[pages.length - 2];
beforePage.$vm.listQuery = Object.assign(beforePage.$vm.listQuery, this.listQuery);
if(beforePage.$vm.listQuery.startTime){
beforePage.$vm.listQuery.sendTime=""
}
beforePage.$vm.tabCurrent = beforePage.$vm.tabList.findIndex(item => item.value == beforePage.$vm.listQuery.contractStatus);
uni.navigateBack({
delta: 1,
success: function() {
beforePage.$vm.refresh();
}
});
更多关于uni-app的loading在安卓设备上不会消失的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3 回复
在 uni-app
中,loading
在安卓设备上不会消失的问题可能由多种原因引起。以下是一些常见的原因和解决方法:
1. 未正确调用 hideLoading
方法
确保在显示 loading
后,调用了 uni.hideLoading()
来隐藏它。如果没有调用 hideLoading
,loading
会一直显示。
uni.showLoading({
title: '加载中...'
});
// 模拟异步操作
setTimeout(() => {
uni.hideLoading(); // 确保调用 hideLoading
}, 2000);
2. 异步操作未完成
如果 loading
是在异步操作中显示的,确保异步操作完成后调用 hideLoading
。例如,在 Promise
或 async/await
中:
async function fetchData() {
uni.showLoading({
title: '加载中...'
});
try {
const res = await uni.request({ url: 'https://example.com/api' });
console.log(res);
} catch (error) {
console.error(error);
} finally {
uni.hideLoading(); // 确保在 finally 中调用 hideLoading
}
}
3. 页面跳转导致 loading
未关闭
如果页面跳转(如 uni.navigateTo
或 uni.redirectTo
)发生在 loading
显示期间,可能会导致 loading
未关闭。可以在页面跳转前手动关闭 loading
:
uni.showLoading({
title: '加载中...'
});
setTimeout(() => {
uni.hideLoading(); // 先关闭 loading
uni.navigateTo({
url: '/pages/nextPage'
});
}, 2000);