Skip to content

Message 提示

用于页面中展示重要的提示信息。

基础用法

<template>
  <ZgButton @click="crtMsg">message</ZgButton>
</template>
<script lang="ts" setup>
import { createMessage } from '@/index'
import { h } from 'vue'

const types = ['success', 'info', 'warning', 'error']
let index = 0
const crtMsg = () => {
  const instance = createMessage({
    message: '这个常规信息!',
    type: types[index % 5] as any,
    offset: 10,
    showIcon: true,
    showClose: true,
  })

  const instance2 = createMessage({
    message: h('p', null, [h('span', null, 'Message can be '), h('i', { style: 'color: teal' }, 'VNode')]),
    type: types[index % 5] as any,
    offset: 10,
    showIcon: true,
    showClose: true,
  })
  console.log('instance:', instance)
  console.log('instance2:', instance2)
  index++
}
</script>

<style>
.block {
  margin-bottom: 10px;
  width: 60%;
}
</style>
<template>
  <ZgButton @click="crtMsg">message</ZgButton>
</template>
<script lang="ts" setup>
import { createMessage } from '@/index'
import { h } from 'vue'

const types = ['success', 'info', 'warning', 'error']
let index = 0
const crtMsg = () => {
  const instance = createMessage({
    message: '这个常规信息!',
    type: types[index % 5] as any,
    offset: 10,
    showIcon: true,
    showClose: true,
  })

  const instance2 = createMessage({
    message: h('p', null, [h('span', null, 'Message can be '), h('i', { style: 'color: teal' }, 'VNode')]),
    type: types[index % 5] as any,
    offset: 10,
    showIcon: true,
    showClose: true,
  })
  console.log('instance:', instance)
  console.log('instance2:', instance2)
  index++
}
</script>

<style>
.block {
  margin-bottom: 10px;
  width: 60%;
}
</style>

不同状态

用来显示「成功、警告、消息、错误」类的操作反馈。

<template>
  <span v-for="item in types" :key="item">
    <ZgButton style="margin-right: 10px" @click="crtMsg(item)">{{ item }}</ZgButton>
  </span>
</template>
<script lang="ts" setup>
import { createMessage, type FeedbackType } from '@/index'

const types = ['success', 'info', 'warning', 'error']

const crtMsg = (type: string) => {
  createMessage({
    message: '这个常规信息!',
    type: type as FeedbackType,
    showIcon: true,
    showClose: true,
  })
}
</script>

<style>
.block {
  margin-bottom: 10px;
  width: 60%;
}
</style>
<template>
  <span v-for="item in types" :key="item">
    <ZgButton style="margin-right: 10px" @click="crtMsg(item)">{{ item }}</ZgButton>
  </span>
</template>
<script lang="ts" setup>
import { createMessage, type FeedbackType } from '@/index'

const types = ['success', 'info', 'warning', 'error']

const crtMsg = (type: string) => {
  createMessage({
    message: '这个常规信息!',
    type: type as FeedbackType,
    showIcon: true,
    showClose: true,
  })
}
</script>

<style>
.block {
  margin-bottom: 10px;
  width: 60%;
}
</style>

Icon Attributes

NameDescriptionTypeDefault
message消息文字string | VNode-
duration显示时间,单位为毫秒。 设为 0 则不会自动关闭number3000
showClose是否显示关闭按钮boolean-
showIcon是否显示类型图标boolean-
type消息类型enum - 'success'| 'warning'| 'error'| 'info'info
offsetMessage 距离窗口顶部的偏移量number20

Released under the MIT License.