Message 消息提示 #
常用于主动操作后的反馈提示。
基础用法 #
从顶部出现,3 秒后自动消失
<template>
<etu-button @click="open">点击展示message</etu-button>
</template>
<script setup lang="ts">
import EtuMessage from "@etu-design/message";
const open = () => {
EtuMessage("33333");
};
</script>
<template>
<etu-button @click="open">点击展示message</etu-button>
</template>
<script setup lang="ts">
import EtuMessage from "@etu-design/message";
const open = () => {
EtuMessage("33333");
};
</script>
不同状态 #
用来显示「成功、警告、消息、错误」类的操作反馈。
<template>
<etu-button @click="open1">success</etu-button>
<etu-button @click="open2">warning</etu-button>
<etu-button @click="open3">message</etu-button>
<etu-button @click="open4">error</etu-button>
</template>
<script lang="ts" setup>
import EtuMessage from "@etu-design/message";
const open1 = () => {
EtuMessage.success("这是一条success消息");
};
const open2 = () => {
EtuMessage.warning("这是一条warning消息");
};
const open3 = () => {
EtuMessage("这是一条message消息");
};
const open4 = () => {
EtuMessage.error("这是一条error消息");
};
</script>
<template>
<etu-button @click="open1">success</etu-button>
<etu-button @click="open2">warning</etu-button>
<etu-button @click="open3">message</etu-button>
<etu-button @click="open4">error</etu-button>
</template>
<script lang="ts" setup>
import EtuMessage from "@etu-design/message";
const open1 = () => {
EtuMessage.success("这是一条success消息");
};
const open2 = () => {
EtuMessage.warning("这是一条warning消息");
};
const open3 = () => {
EtuMessage("这是一条message消息");
};
const open4 = () => {
EtuMessage.error("这是一条error消息");
};
</script>
可关闭的消息提示 #
可以添加关闭按钮。
设置showClose
以手动关闭
<template>
<etu-button @click="open1">success</etu-button>
<etu-button @click="open2">warning</etu-button>
<etu-button @click="open3">message</etu-button>
<etu-button @click="open4">error</etu-button>
</template>
<script lang="ts" setup>
import EtuMessage from "@etu-design/message";
const open1 = () => {
EtuMessage({
type: "success",
message: "这是一条可关闭的success消息",
showClose: true,
});
};
const open2 = () => {
EtuMessage({
type: "warning",
message: "这是一条可关闭的warning消息",
showClose: true,
});
};
const open3 = () => {
EtuMessage({
message: "这是一条可关闭的message消息",
showClose: true,
});
};
const open4 = () => {
EtuMessage({
type: "error",
message: "这是一条可关闭的error消息",
showClose: true,
});
};
</script>
<template>
<etu-button @click="open1">success</etu-button>
<etu-button @click="open2">warning</etu-button>
<etu-button @click="open3">message</etu-button>
<etu-button @click="open4">error</etu-button>
</template>
<script lang="ts" setup>
import EtuMessage from "@etu-design/message";
const open1 = () => {
EtuMessage({
type: "success",
message: "这是一条可关闭的success消息",
showClose: true,
});
};
const open2 = () => {
EtuMessage({
type: "warning",
message: "这是一条可关闭的warning消息",
showClose: true,
});
};
const open3 = () => {
EtuMessage({
message: "这是一条可关闭的message消息",
showClose: true,
});
};
const open4 = () => {
EtuMessage({
type: "error",
message: "这是一条可关闭的error消息",
showClose: true,
});
};
</script>
Message配置项 #
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
message | 消息文字 | string / VNode / (() => VNode) | — |
type | 消息类型 | 'success' / 'warning' / 'info' / 'error' | 'info' |
duration | 显示时间,单位为毫秒。 设为 0 则不会自动关闭 | number | 3000 |
show-close | 是否显示关闭按钮 | boolean | false |
on-close | 关闭时的回调函数, 参数为被关闭的 message 实例 | function | — |
offset | Message 距离窗口顶部的偏移量 | number | 20 |
Message方法 #
方法名 | 描述 |
---|---|
close | 关闭当前的 Message |