Skip to content
iuiDesign
100%
02:32
本页目录

展示通知提醒,将信息及时有效的传达给用户。

基本使用

消息通知的基本用法

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

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

  const notify = ref(null);
  onMounted(() => {
    notify.value.push({ content: "通知内容" }); 
  });
</script>
<iui-notify ref="notify"> </iui-notify> 

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

  const notify = ref(null);
  onMounted(() => {
    notify.value.push({ content: "通知内容" }); 
  });
</script>

消息类型

消息通知有四种类型,分别为 primarysuccesswarningerror,默认为 primary

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

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

  const notify = ref(null);
  onMounted(() => {
    // 通过函数调用
    notify.value.push({ content: "主要通知" }); 
    notify.value.success({ content: "成功通知" }); 
    notify.value.warning({ content: "警告通知" }); 
    notify.value.error({ content: "错误通知" }); 

    // 通过属性调用
    notify.value.push({ content: "成功通知", type: "success" }); 
  });
</script>
<iui-notify ref="notify"> </iui-notify> 

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

  const notify = ref(null);
  onMounted(() => {
    // 通过函数调用
    notify.value.push({ content: "主要通知" }); 
    notify.value.success({ content: "成功通知" }); 
    notify.value.warning({ content: "警告通知" }); 
    notify.value.error({ content: "错误通知" }); 

    // 通过属性调用
    notify.value.push({ content: "成功通知", type: "success" }); 
  });
</script>

自定义

notify 支持通过属性传入自定义内容。

html
<iui-notify ref="notify">
    <!-- 自定义内容 -->
    <template #content="{ msg }">
      <view class="customContent">
        {{ msg }}
      </view>
    </template>
</iui-notify>

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

  const notify = ref(null);
  onMounted(() => {
    notify.value.push({
      content: "通知内容",
      // 自定义文字颜色、背景色
      color: {
        background: "rgb(232, 243, 255)",
        color: "#165DFF",
      },
    });
  });
</script>

<style scoped>
.customContent {
  border: 1px solid #165dff;
  border-radius: 50px;
  padding: 5px 20px;
  margin-top: 5px;
  color: #165dff;
}
</style>
<iui-notify ref="notify">
    <!-- 自定义内容 -->
    <template #content="{ msg }">
      <view class="customContent">
        {{ msg }}
      </view>
    </template>
</iui-notify>

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

  const notify = ref(null);
  onMounted(() => {
    notify.value.push({
      content: "通知内容",
      // 自定义文字颜色、背景色
      color: {
        background: "rgb(232, 243, 255)",
        color: "#165DFF",
      },
    });
  });
</script>

<style scoped>
.customContent {
  border: 1px solid #165dff;
  border-radius: 50px;
  padding: 5px 20px;
  margin-top: 5px;
  color: #165dff;
}
</style>

API

<Notify>props
参数描述类型默认值
content消息内容String-
visible是否显示Booleanfalse
timeout显示时长Number2000
type消息类型primary | success | warning | errorprimary
color自定义颜色Object:{background: String, color: String}-
height高度Number40
fixed是否固定在顶部Booleanfalse
<Notify>slots
插槽名描述参数
content自定义内容消息内容 msg: String