示例仅供参考,请以真机为主

Toast 吐司提示

方法

事件名称说明参数
open打开function(option: Options)

Options 有效值

参数说明类型可选值默认值
icon图标类名string
image图片objectnull
image.url图片地址string
image.mode图片裁剪模式stringaspectFit
image.style图片样式object
message提示消息string
duration保留时长number2000
type类型stringprimary / success / error / warning / info
position悬浮位置stringtop / middle / bottombottom
single是否单个显示booleanfalse

示例

使用 ref 获取组件实例并添加 ClToast.Ref 类型提示

<template>
	<view class="demo">
		<cl-toast ref="Toast"></cl-toast>
		<cl-button @tap="open">提示</cl-button>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	const Toast = ref<ClToast.Ref>();

	function open() {
		Toast.value?.open({
			message: "Toast 提示"
		});
	}
</script>

不同类型

配置 type 参数:

<template>
	<view class="demo">
		<cl-toast ref="Toast"></cl-toast>
		<cl-button @tap="open">提示</cl-button>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	const Toast = ref<ClToast.Ref>();

	function open() {
		Toast.value?.open({
			message: "Toast 提示",
			type: "primary" // warning error info success
		});
	}
</script>

不同位置

配置 position 参数:

<template>
	<view class="demo">
		<cl-toast ref="Toast"></cl-toast>
		<cl-button @tap="open">提示</cl-button>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	const Toast = ref<ClToast.Ref>();

	function open() {
		Toast.value?.open({
			message: "Toast 提示",
			position: "top" // top middle bottom
		});
	}
</script>

添加图片、图标

<template>
	<view class="demo">
		<cl-toast ref="Toast"></cl-toast>
		<cl-button @tap="open">图标</cl-button>
		<cl-button @tap="open2">图片</cl-button>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	const Toast = ref<ClToast.Ref>();

	function open() {
		Toast.value?.open({
			message: "Toast 提示",
			icon: "cl-icon-good-fill"
		});
	}

	function open2() {
		Toast.value?.open({
			message: "Toast 提示",
			image: {
				url: "../static/avatar.png",
				style: {
					height: "120rpx",
					width: "120rpx"
				}
			}
		});
	}
</script>
Last Updated: