Message

Used to show feedback after an activity. The difference with Notification is that the latter is often used to show a system level passive notification.

Basic usage

Displays at the top, and disappears after 3 seconds. The setup of Message is very similar to notification, so parts of the options won't be explained in detail here. You can check the options table below combined with notification doc to understand it. Bigin UI has registered a $message method for invoking. Message can take a string or a VNode as parameter, and it will be shown as the main body.

Types

Used to show the feedback of Success, Warning, Message and Error activities. When you need more customizations, Message component can also take an object as parameter. For example, setting value of type can define different types, and its default is info. In such cases the main body is passed in as the value of message. Also, we have registered methods for different types, so you can directly call it without passing a type like open4.

Closable

A close button can be added. A default Message cannot be closed manually. If you need a closable message, you can set showClose field. Besides, same as notification, message has a controllable duration. Default duration is 3000 ms, and it won't disappear when set to 0.

Centered Text

Use the center attribute to center the text.

Use HTML String

message supports HTML string. Set dangerouslyUseHTMLString to true and message will be treated as an HTML string.

WARNING

Although message property supports HTML strings, dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to XSS attacksopen in new window. So when dangerouslyUseHTMLString is on, please make sure the content of message is trusted, and never assign message to user-provided content.

Grouping

Merge messages with the same content.

Set grouping to true and the same content of message will be merged.

Global Method

Bigin UI has added a global method $message for app.config.globalProperties. So in a vue instance you can call Message like what we did in this page.

Local Import

import { BMessage } from 'bigin-ui'

In this case you should call BMessage(options). We have also registered methods for different types, e.g. BMessage.success(options). You can call BMessage.closeAll() to manually close all the instances.

App context inheritance

Now message accepts a context as second parameter of the message constructor which allows you to inject current app's context to message which allows you to inherit all the properties of the app.

You can use it like this:

TIP

If you globally registered BMessage component, it will automatically inherit your app context.

import { getCurrentInstance } from 'vue'
import { BMessage } from 'bigin-ui'
// in your setup method
const { appContext } = getCurrentInstance()!
BMessage({}, appContext)

Options

AttributeDescriptionTypeDefault
messagemessage textstring / VNode / (() => VNode)
typemessage typesuccess / warning / info / errorinfo
iconcustom icon component, overrides typestring / Component
dangerouslyUseHTMLStringwhether message is treated as HTML stringbooleanfalse
custom-classcustom class name for Messagestring
durationdisplay duration, millisecond. If set to 0, it will not turn off automaticallynumber3000
show-closewhether to show a close buttonbooleanfalse
centerwhether to center the textbooleanfalse
on-closecallback function when closed with the message instance as the parameterfunction
offsetset the distance to the top of viewportnumber20
appendToset the root element for the messagestring / HTMLElementdocument.body
groupingmerge messages with the same content, type of VNode message is not supportedbooleanfalse

Methods

Message and this.$message returns the current Message instance. To manually close the instance, you can call close on it.

MethodDescription
closeclose the Message
Last Updated:
Contributors: Tam Mai