# Toast 消息提示 
该组件主要用于消息通知、加载提示、操作结果提示等醒目提示效果,我们提供了多种丰富的API,类似于uni.showToastAPI。
# 平台兼容性
| App(vue) | App(nvue) | H5 | 小程序 | VUE2 | VUE3 |
|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ |
# 基本使用
以下为不同能力的toast的具体表现。使用ref调用组件内部的show方法进行显示,并传递参数,参数参数下方Toast Params
<template>
<view>
<uv-toast ref="toast"></uv-toast>
<view class="list">
<view class="item" v-for="(item,index) in list" :key="index" @click="showToast(item)">{{item.title}}</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
list: [{
type: 'default',
title: '默认主题',
message: "锦瑟无端五十弦"
}, {
type: 'error',
icon: false,
title: '失败主题',
message: "一弦一柱思华年"
}, {
type: 'success',
title: '成功主题(带图标)',
message: "庄生晓梦迷蝴蝶"
}, {
type: 'loading',
title: '正在加载',
message: "正在加载"
}, {
type: 'default',
title: '结束后跳转标签页',
message: "此情可待成追忆",
url: '/pages/componentsD/tag/tag'
}]
}
},
methods: {
showToast(params) {
this.$refs.toast.show({
...params,
complete() {
params.url && uni.navigateTo({
url: params.url
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.item {
margin: 10rpx 0;
padding: 10rpx;
text-align: center;
background: #f1f1f1;
font-size: 28rpx;
color: #666;
}
</style>
# 完整示例
# API
# Toast Params
这些参数为通过ref调用<toast/>组件内部的show方法时,需要传递参数,如:
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| loading | 是否加载中 | Boolean | false | true | false |
| z-index | toast展示时的层级 | String | Number | 10090 | - |
| overlay | 是否显示透明遮罩,防止点击穿透 | Boolean | true | true | false |
| message | 显示的文本 | String | Number | - | - |
| icon | 图标,或者绝对路径的图片 | String | - | - |
| position | toast出现的位置 | String | center | top | bottom |
| type | 主题类型 | String | - | - |
| params | 跳转的参数 | Object | - | - |
| duration | 展示时间,单位ms | String | Number | 2000 | - |
| complete | 执行完后的回调函数 | Function | null | - |
# Toast Methods
方法是通过ref调用
注意
注意:所有有关ref的调用,都不能在页面的onLoad生命周期调用,因为此时组件尚未创建完毕,会报错,应该在onReady生命周期调用。
| 方法名 | 说明 | 参数 |
|---|---|---|
| show | 显示toast,如需一进入页面就显示toast,请在onReady生命周期调用 | 见上方说明Toast Params |
| hide | 隐藏toast | - |