::: sourceCode ## uni.showLoading(options?) @showloading > issues: https://issues.dcloud.net.cn/?mid=api.ui.loading.showLoading > 源码: https://github.com/dcloudio/uni-app/tree/uni-app-x-alpha/src/uni_modules/uni-showLoading ::: 显示 loading 提示框, 需主动调用 uni.hideLoading 才能关闭提示框。 它是一个悬浮弹出的、非组件内嵌的加载中提示。 ### showLoading 兼容性 Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 ### 参数 | 名称 | 类型 | 必填 | 描述 | | :- | :- | :- | :- | | options | **ShowLoadingOptions** | 否 | uni.showLoading参数定义 | #### options 的属性描述 | 名称 | 类型 | 必备 | 兼容性 | 描述 | | :- | :- | :- | :-: | :- | | title | string | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | 提示的内容,长度与 icon 取值有关。 | | mask | boolean | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: x; iOS: x; HarmonyOS: x | 是否显示透明蒙层,防止触摸穿透,默认:false | | success | (res: [ShowLoadingSuccess](#showloadingsuccess-values)) => void | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | uni.showLoading成功回调函数定义 | | fail | (res: [ShowLoadingFail](#showloadingfail-values)) => void | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | uni.showLoading失败回调函数定义 | | complete | (res: any) => void | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | uni.showLoading完成回调函数定义 | #### ShowLoadingSuccess 的属性值 @showloadingsuccess-values | 名称 | 类型 | 必备 | 兼容性 | 描述 | | :- | :- | :- | :-: | :- | | errMsg | string | 是 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | 错误信息 | #### ShowLoadingFail 的属性值 @showloadingfail-values | 名称 | 类型 | 必备 | 描述 | | :- | :- | :- | :- | | errCode | number | 是 | uni.showLoading失败回调参数 | | errSubject | string | 是 | 统一错误主题(模块)名称 | | data | any | 否 | 错误信息中包含的数据 | | cause | [Error](/err-spec.md#unierror) | 否 | 源错误信息,可以包含多个错误,详见SourceError | | errMsg | string | 是 | | ### 返回值 | 类型 | 必备 | | :- | :- | | [UniPage](/api/unipage.md) | 否 | ::: sourceCode ## uni.hideLoading(options?) @hideloading > issues: https://issues.dcloud.net.cn/?mid=api.ui.loading.hideLoading > 源码: https://github.com/dcloudio/uni-app/tree/uni-app-x-alpha/src/uni_modules/uni-prompt ::: 隐藏 loading 提示框。 ### hideLoading 兼容性 Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 ### 参数 | 名称 | 类型 | 必填 | 描述 | | :- | :- | :- | :- | | options | **HideLoadingOptions** | 否 | uni.hideLoading参数定义 | #### options 的属性描述 | 名称 | 类型 | 必备 | 兼容性 | 描述 | | :- | :- | :- | :-: | :- | | loadingPage | [UniPage](/api/unipage.md) | 否 | Web: 4.0; 微信小程序: x; 支付宝小程序: x; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | 期望隐藏的目标LoadingPage 如果为null 会关闭当前栈顶全部LoadingPage | | success | (res: [HideLoadingSuccess](#hideloadingsuccess-values)) => void | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | uni.hideLoading成功回调函数定义 | | fail | (res: [HideLoadingFail](#hideloadingfail-values)) => void | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | uni.hideLoading失败回调函数定义 | | complete | (res: any) => void | 否 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | uni.hideLoading完成回调函数定义 | | noConflict | boolean | 否 | 微信小程序: 4.41 | 需要基础库: `2.22.1`

目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
| #### HideLoadingSuccess 的属性值 @hideloadingsuccess-values | 名称 | 类型 | 必备 | 兼容性 | 描述 | | :- | :- | :- | :-: | :- | | errMsg | string | 是 | Web: 4.0; 微信小程序: 4.41; 支付宝小程序: 5.31; Android: 4.61; iOS: 4.61; HarmonyOS: 4.61 | 错误信息 | #### HideLoadingFail 的属性值 @hideloadingfail-values | 名称 | 类型 | 必备 | 描述 | | :- | :- | :- | :- | | errCode | number | 是 | uni.hideLoading失败回调参数 | | errSubject | string | 是 | 统一错误主题(模块)名称 | | data | any | 否 | 错误信息中包含的数据 | | cause | [Error](/err-spec.md#unierror) | 否 | 源错误信息,可以包含多个错误,详见SourceError | | errMsg | string | 是 | | ## 示例 示例为[hello uni-app x alpha分支](https://gitcode.com/dcloud/hello-uni-app-x/blob/prod_alpha/pages/API/loading/loading.uvue),与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例[另见](https://gitcode.com/dcloud/hello-uni-app-x/blob/master//pages/API/loading/loading.uvue) ::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/loading/loading > appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/loading/loading >示例 ```vue ``` ::: ## 通用类型 ### GeneralCallbackResult @generalcallbackresult-values | 名称 | 类型 | 必备 | 描述 | | :- | :- | :- | :- | | errMsg | string | 是 | 错误信息 | ## Tips@tips * 关于uni.showLoading和[loading组件](../component/loading.md)的区别: + showLoading是一个简易的API,使用简单。因为它悬浮在页面上方、让页面整体失去响应。主流的App较少使用这种方式。 + loading组件是内置组件,无需在页面显式引入,可以嵌入页面中、按钮中。 * 从HBuilderX 5.0+,在App和Web平台,showLoading统一成一套代码,使用dialogPage的页面中显示一个loading组件来实现。dialogPage是模态的,不支持点击空白消失,但支持back关闭。需要非模态的使用场景时,请在页面中直接使用[loading组件](../component/loading.md)。 * showLoading 是和页面(包括 dialogPage)绑定的。 + 当showLoading执行时,会寻找当前页面栈顶的窗体(包括 dialogPage),找到后进行绑定,然后弹出loading。 + 在弹出loading后,再次打开新页面,新页面会覆盖原页面弹出的 loading。 + 如需在新页面(包括 dialogPage)弹出 loading,需要再次调用 showLoading * 在HBuilderX 5.0以前,HarmonyOS 平台,showLoading 是和 App window 绑定的,目前未与页面关联,当打开新页面时,原页面弹出的 loading 不会被遮挡。HBuilderX 5.0拉齐了实现,与上条策略一致。 * 当前页面(包括 dialogPage)关闭时,弹出的 loading 都会被自动取消 + 如需在dialogPage关闭后,仍然弹出 Loading,需要在关闭dialogPage后再次调用 showLoading + 注意在支持 dialogPage 的平台(Web和App),[uni.showModal](./modal.md)、[uni.showActionSheet](./action-sheet.md) 也是 dialogPage 实现的,此时 showLoading 会绑定到这些 dialogPage 上 * 在 Web 平台,如果希望通过 `const loadingPage = uni.showLoading(...)` 获取 `loadingPage` 对象,需要至少传入一个回调函数,例如: ```ts uni.showLoading({ success: function (showRet : ShowLoadingSuccess) { } }) ```