Skip to content

Message

可直接用于展示,或用 API 操作新建实例展示

基础用法

通过 import Message from 'my-element' 使用

由于 VitePress 自身bug , 服务端渲染导致 document 未找到,一直没解决,build 出来的暂时不给例子了

html
<template>
  <Message type="info" message="hello Message" />
  <Message type="primary" message="hello Primary" />
  <Message type="danger" message="hello Danger" />
  <Message type="success" message="hello Success" />
</template>

<script setup>
import Message from '@/components/Message/Message.vue'
</script>

createMessage

html
<template>
  <Button @click="onMsg1">打开消息1 - info</Button>
  <Button @click="onMsg2">打开消息2 - primary</Button>
  <Button @click="onMsg3">打开消息3 - success</Button>
  <Button @click="onMsg4">打开消息4 - danger</Button>
</template>

<script setup>
import Button from '@/components/Button/Button.vue'
import { createMessage } from '@/components/Message/createMessage'
const onMsg1 = () => {
  createMessage({ message: '打开消息1 - info', duration: 3000 })
}
const onMsg2 = () => {
  createMessage({ type: 'success', message: '打开消息2 - primary', duration: 0, showClose: true })
}
const onMsg3 = () => {
  createMessage({ type: 'danger', message: '打开消息3 - success', duration: 0, showClose: true })
}
const onMsg4 = () => {
  createMessage({ type: 'danger', message: '打开消息4 - danger', duration: 0, showClose: true })
}
</script>

Props

键名描述类型默认值
message消息内容string / VNode-
durationmessage 持续时间number4000 (毫秒)
showClose是否有 close Icon 可手动关闭booleanfalse
type默认提供四种类型支持success、info、warning、dangerinfo
transitionName过渡效果stringfade
onDestory组件销毁方法Function-
offset偏移位置number0

Instance

键名描述类型默认值
id实例对应 idstring-
zIndex实例生成的 z-indexnumber4000 (毫秒)