4.0.2 • Published 1 year ago

vue-m-message v4.0.2

Weekly downloads
656
License
MIT
Repository
github
Last release
1 year ago

vue-m-message

A message plugin base on Vue.

v4.x version only supports Vue 3; If you use Vue 2, use v3.x instead.

Preview

中文 | Live Demo

npm install vue-m-message

# Vue 2
# npm install vue-m-message@3
import { createApp, h } from 'vue'
import Message from 'vue-m-message'
import 'vue-m-message/dist/style.css'
import App from './App.vue'

const app = createApp(App)

app.use(Message)
// or
app.use(Message, options: { name?: string, defaultOptions?: MessageTypeOptions })

// Message.info('Wellcome here !', { duration: -1, ctx: instance?.appContext })
// Message.info(h('m-demo', 'Wellcome here !'), { duration: -1 })
Message.info(() => h('div', [
  'Here is playground for ',
  h('a', { href: 'https://github.com/mengdu/m-message' },'Vue Message'),
  ' plugin.'
]), {
  title: 'Wellcome here !',
  duration: -1,
  iconURL: 'https://avatars.githubusercontent.com/u/11366654?s=40&v=4'
})
// Message.info(<m-demo>Wellcome here !</m-demo>, { duration: -1 })
// Message.info(() => <m-demo>Wellcome here !</m-demo>, { duration: -1 })

app.mount('#app')

Message API

  • Message(options: MessageOptions): MessageIntance General prompt information
  • Message.info(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Info prompt information
  • Message.success(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Success prompt information
  • Message.error(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Error prompt information
  • Message.warning(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Warning prompt information
  • Message.loading(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Loading prompt information
  • Message.closeAll(): void Clear all prompts
  • Message.setDefault(options: MessageTypeOptions): void Set default values
type MessageTypeOptions = Omit<MessageOptions, 'type' | 'message'>

interface MessageIntance {
  id: string
  close: () => void
}

MessageOptions

AttributeDescriptionTypeOptional valueDefault
typeMessage type iconstring'', 'info', 'success', 'error', 'warning', 'loading''info'
iconURLReplace type icon with picturestring
titleMessage titlestring''
messageMessage contentstring''
positionMessage display positionstring'top-left', 'top-center', 'top-right', 'center', 'bottom-left', 'bottom-center', 'bottom-right'
durationMessage display duration, in MS; When ` - 1 ', it needs to be closed manually | number | — | 3000
widthMessage block width, auto width by defaultstring''
classNameclass namestring
wrapperClassNameclass name for wrapperstring
zIndexz-indexnumber1010
supportHTMLWhether the message content supports HTML (only valid when the message is a string)booleantrue/falsefalse
isCollapsedCollapse contentbooleantrue/falsefalse
collapsableCollapsablebooleantrue/falsefalse
closableWhether it can be closedbooleantrue/falsefalse
hasMaskDoes it contain a maskbooleantrue/falsefalse
stopTimerOnHoverWhether to recalculate the display duration when the mouse moves overbooleantrue/falsetrue
onCloseClose callback() => void
onCollapsedFold switch callback(collapsed: boolean) => void

License

Licensed as MIT.