1.5.0 • Published 12 months ago

vue-message-plugin-ts v1.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

vue-message-plugin-ts

A message plugin base on Vue with Typescript support

supports only Vue 3

Preview

Docs page | Live Demo

Installation

you can install the package yarn:

yarn add vue-message-plugin-ts

or npm:

npm i vue-message-plugin-ts

Register Plugin

import { createApp, h } from 'vue'
import Message from 'vue-message-plugin-ts'
import 'vue-message-plugin-ts/dist/style.css'
import App from './App.vue'

const app = createApp(App)

app.use(Message)
// or
app.use(Message, options?: { position?: IMessagesOption } as IMessagesOption)

app.mount('#app')

Usage

// App.vue
<template>
  <app-messages />
  <component :is="layoutName">
    <RouterView />
  </component>
</template>

Usage in components

// Component.vue
<script lang="ts" setup>
import { inject } from 'vue'

const message = inject('message')

function errorAction () {
  message.addNewMessage({
    title: 'Action error',
    type: 'error',
    duration: 5000,
  })
}

function startWait () {
  message.startWait()
}

function stopWait () {
  message.stopWait()
}

</script>

Messages API

MessagesOption

AttributeDescripttionTypeOptional valueDefault
positionMessages display positionstring‘top-left’, ‘top-center’, ‘top-right’, ‘right-center’, ‘bottom-right’, ‘botom-center’, ‘bottom-left’, ‘left-center’‘top-right’

Messages

AttributeDescripttionTypeOptional valueDefault
addNewMessageAdding a new message(message: IMessageItem) ⇒ voidIMessageItem
removeMessageRemove message by id(id: TMessageId) ⇒ voidTMessageId
startWaitWait loader message(message?: IMessageItem) ⇒ voidIMessageItem
stopWaitStop wait loader message(id?: TMessageId) ⇒ voidTMessageId

Message for create (Message)

AttributeDescripttionTypeOptional valueDefaultrequired
bodyBody of messageTMessageFieldtrue
durationDuration of message, if you don't add duration then you have to remove it yourselfnumberfalse
typeType of messageTMessageTypes‘error’, ‘success’, ‘warning’, ‘custom’, ‘wait’true
imgIcon image of messageTMessageFieldfalse
classClass of messageTMessageClassfalse
key?: stringKey of messagestringfalse

Types List

  • type TMessageField = string | {value: string | any, class: TMessageClass}
  • type TMessageTypes = ‘error’ | ‘success’ | ‘warning’ | ‘custom’ | ‘wait’
  • type TMessageClass = string | string[]
  • type TMessageId = number | string

Template, Slot names

NameDescripttionValue
message__img-waitMessage slot name for wait messages icon imageIMessageItem
message__img-successMessage slot name for success messages icon imageIMessageItem
message__img-errorMessage slot name for error messages icon imageIMessageItem
message__img-warningMessage slot name for warning messages icon imageIMessageItem
message__img-customMessage slot name for custom messages icon imageIMessageItem
message__title-waitMessage slot name for wait messages titleIMessageItem
message__title-successMessage slot name for success messages titleIMessageItem
message__title-warningMessage slot name for warning messages titleIMessageItem
message__title-errorMessage slot name for error messages titleIMessageItem
message__title-customMessage slot name for custom messages titleIMessageItem

Tip !!

You can add wait message with method startWait and this method creates default message, if you want to add custom wait message you can use method addNewMessage() and then if you want to stop this custom message u can use stopWait agait but with argument id that has been given when created message so you can create default wait message also custom wait message

License

Licensed as MIT.

1.2.0

12 months ago

1.1.0

12 months ago

1.5.0

12 months ago

1.2.2

12 months ago

1.3.0

12 months ago

1.0.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago