# uni.showToast(options)

显示消息提示框

# showToast 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS
4.0 4.41 3.91 4.11 4.11 4.61

# 参数

名称 类型 必填 默认值 兼容性 描述
options ShowToastOptions uni.showToast参数定义
名称 类型 必备 默认值 兼容性 描述
title string
提示的内容,长度与 icon 取值有关。
icon string "success"
icon值说明
合法值 描述
success 显示成功图标
error 显示错误图标
fail 显示错误图标,此时title文本无长度显示,支付宝、抖音小程序生效
exception 显示异常图标,此时title文本无长度显示,支付宝小程序生效
loading 显示加载图标
none 不显示图标
image string.ImageURIString
自定义图标的本地路径(app端暂不支持gif)
mask boolean false
是否显示透明蒙层,防止触摸穿透
duration number 1500
提示的延迟时间,单位毫秒
position string
position值说明。纯文本轻提示显示位置,填写有效值后只有 title 属性生效,且不支持通过 uni.hideToast 隐藏。
合法值 描述
top 居上显示
center 居中显示
bottom 居底显示
success (res: ShowToastSuccess) => void
uni.showToast成功回调函数定义
fail (res: ShowToastFail) => void
uni.showToast失败回调函数定义
complete (res: any) => void
uni.showToast完成回调函数定义

# ShowToastFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number 错误码
合法值 描述
1 撤销
1001 请求参数非法
errSubject string 统一错误主题(模块)名称
data any 错误信息中包含的数据
cause Error 源错误信息,可以包含多个错误,详见SourceError
errMsg string

# 参见

# 注意事项

  • App平台 position 参数特别说明

如果没有设置 position 字段,uni.showToast 会采用应用弹窗方案,即弹窗与页面生命周期绑定。 页面关闭时,当前页面弹出的所有弹窗都会被自动取消。

如果设置了position 字段,uni.showToast 会采用系统弹窗方案,即弹窗与页面无绑定关系。 页面关闭后,弹出中的/等待弹出的Toast会继续展示。

系统弹窗在部分系统(比如 MIUI,Google)可能会有应用图标前缀。

系统弹窗在部分系统(比如 鸿蒙 4.0以上)可能不支持顶部和居中展示。

# uni.hideToast()

隐藏消息提示框。

# hideToast 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS
4.0 4.41 3.91 4.11 4.11 4.61

# 参见

# uni.showLoading(options)

显示 loading 提示框, 需主动调用 uni.hideLoading 才能关闭提示框。

# showLoading 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS
4.0 4.41 4.61 4.61 4.61 4.61

# 参数

名称 类型 必填 默认值 兼容性 描述
options ShowLoadingOptions uni.showLoading参数定义
名称 类型 必备 默认值 兼容性 描述
title string
提示的内容,长度与 icon 取值有关。
mask boolean
是否显示透明蒙层,防止触摸穿透,默认:false
success (res: ShowLoadingSuccess) => void
uni.showLoading成功回调函数定义
fail (res: ShowLoadingFail) => void
uni.showLoading失败回调函数定义
complete (res: any) => void
uni.showLoading完成回调函数定义

# ShowLoadingSuccess 的属性值

名称 类型 必备 默认值 兼容性 描述
errMsg string
错误信息

# ShowLoadingFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number uni.showLoading失败回调参数
errSubject string 统一错误主题(模块)名称
data any 错误信息中包含的数据
cause Error 源错误信息,可以包含多个错误,详见SourceError
errMsg string

# 返回值

类型 必备
UniPage

# 参见

# uni.hideLoading()

隐藏 loading 提示框。

# 参数

名称 类型 必填 默认值 兼容性 描述
options HideLoadingOptions uni.hideLoading参数定义
名称 类型 必备 默认值 兼容性 描述
loadingPage UniPage
期望隐藏的目标LoadingPage 如果为null 会关闭当前栈顶全部LoadingPage
success (res: HideLoadingSuccess) => void
uni.hideLoading成功回调函数定义
fail (res: HideLoadingFail) => void
uni.hideLoading失败回调函数定义
complete (res: any) => void
uni.hideLoading完成回调函数定义
noConflict boolean
需要基础库: 2.22.1

目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性

# HideLoadingSuccess 的属性值

名称 类型 必备 默认值 兼容性 描述
errMsg string
错误信息

# HideLoadingFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number uni.hideLoading失败回调参数
errSubject string 统一错误主题(模块)名称
data any 错误信息中包含的数据
cause Error 源错误信息,可以包含多个错误,详见SourceError
errMsg string

# hideLoading 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS
4.0 4.41 4.61 4.61 4.61 4.61

# 参见

# uni.showModal(options)

显示模态弹窗,可以只有一个确定按钮,也可以同时有确定和取消按钮。类似于一个API整合了 html 中:alert、confirm。

# showModal 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS
4.0 4.41 4.61 4.61 4.61 4.61

# 参数

名称 类型 必填 默认值 兼容性 描述
options ShowModalOptions
名称 类型 必备 默认值 兼容性 描述
title string
提示的标题
content string
提示的内容
showCancel boolean true
是否显示取消按钮,默认为 true
cancelText string
取消按钮的文字,默认为"取消"
cancelColor string.ColorString
取消按钮的文字颜色,默认为"#000000"
confirmText string
确定按钮的文字,默认为"确定"
confirmColor string.ColorString
确定按钮的文字颜色
editable boolean false
是否显示输入框
placeholderText string
显示输入框时的提示文本
success (result: ShowModalSuccess) => void
接口调用成功的回调函数
fail (result: ShowModalFail) => void
接口调用失败的回调函数
complete (result: any) => void
接口调用结束的回调函数(调用成功、失败都会执行)

# ShowModalSuccess 的属性值

名称 类型 必备 默认值 兼容性 描述
errMsg string
错误信息
content string
editable 为 true 时,用户输入的文本
cancel boolean
为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭)
confirm boolean
为 true 时,表示用户点击了确定按钮

# ShowModalFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number
errSubject string 统一错误主题(模块)名称
data any 错误信息中包含的数据
cause Error 源错误信息,可以包含多个错误,详见SourceError
errMsg string

# 返回值

类型 必备
UniPage

# 参见

# uni.showActionSheet(options)

从底部向上弹出操作菜单

# showActionSheet 兼容性

Web 微信小程序 Android iOS iOS uni-app x UTS 插件 HarmonyOS
4.0 4.41 3.91 4.11 4.11 4.61

# 参数

名称 类型 必填 默认值 兼容性 描述
options ShowActionSheetOptions
参数说明
名称 类型 必备 默认值 兼容性 描述
title string
菜单标题
alertText string
警示文案(仅微信小程序真机有效)
itemList Array<string>
按钮的文字数组
itemColor string.ColorString
按钮的文字颜色,字符串格式
popover Popover
大屏设备弹出原生选择按钮框的指示区域,默认居中显示
名称 类型 必备 默认值 兼容性 描述
top number
指示区域坐标,使用原生 navigationBar 时一般需要加上 navigationBar 的高度
left number
指示区域坐标
width number
指示区域宽度
height number
指示区域高度
titleColor string.ColorString
菜单标题文字颜色,字符串格式
cancelText string
取消按钮的文字,默认为"取消"
cancelColor string.ColorString
取消按钮的文字颜色,字符串格式
backgroundColor string.ColorString
弹框背景颜色
success (result: ShowActionSheetSuccess) => void
接口调用成功的回调函数
fail (result: ShowActionSheetFail) => void
接口调用失败的回调函数
complete (result: any) => void
接口调用结束的回调函数(调用成功、失败都会执行)

# ShowActionSheetSuccess 的属性值

名称 类型 必备 默认值 兼容性 描述
errMsg string
错误信息
tapIndex number
用户点击的按钮序号,从上到下的顺序,从0开始

# ShowActionSheetFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number 错误码
- 4: 框架内部异常
errSubject string 统一错误主题(模块)名称
data any 错误信息中包含的数据
cause Error 源错误信息,可以包含多个错误,详见SourceError
errMsg string

itemList,即actionsheet的列表项,在app和小程序上最多6项,超出会报错。在web上超出不报错,列表区变为可滚动。

# 参见

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 兼容性 描述
errMsg string
错误信息

# Bug & Tips