Skip to content
iuiDesign
100%
17:44
本页目录

用于轻量级反馈或提示,不会打断用户操作。

基本使用

轻提示的基本用法

html
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.show("Tips");
  });
</script>
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.show("Tips");
  });
</script>

显示位置

Toast 可以显示在 顶部、中间、底部,默认显示在中间。
可以通过 position 属性设置显示位置。

html
<iui-toast ref="toast" position="top"></iui-toast>
<!-- or -->
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.show({
      message: "Tips",
      position: "top",
    });
  });
</script>
<iui-toast ref="toast" position="top"></iui-toast>
<!-- or -->
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.show({
      message: "Tips",
      position: "top",
    });
  });
</script>

带状态的提示

Toast 除了基本的提示,还额外内置了三种状态提示,分别是 successerrorloading
可以通过 type 设置提示类型。

html
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.show({
      message: "Success tips",
      type: "success",
    });
  });
</script>
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.show({
      message: "Success tips",
      type: "success",
    });
  });
</script>

加载中提示

Toast 还内置了 showLoadinghideLoading 方法。用于显示和隐藏加载中提示。

html
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.showLoading("Loading...");
  });
</script>
<iui-toast ref="toast"></iui-toast>

<script setup>
  import { ref } from "vue";

  const toast = ref();
  onMounted(() => {
    toast.value.showLoading("Loading...");
  });
</script>

API

<Toast>props
参数描述类型默认值
message提示的内容String-
type消息类型success | error | warning-
duration提示的持续时间Number3000
position显示提示的位置top | bottom | centercenter
icon自定义图标,支持所有内置图标String-
direction图标和文字的排列方向horizontal | verticalvertical
mask是否显示透明蒙层,防止触摸穿透Booleanfalse
<Toast>methods
方法名描述参数
show显示提示props: Object
showLoading显示加载提示props: Object
hideLoading隐藏加载提示-