Vue M Message

4.0.2 · active · verified Sun Apr 19

vue-m-message is a lightweight and configurable message/toast plugin designed specifically for Vue.js applications. The current stable version, v4.0.2, exclusively supports Vue 3, having been fully refactored with TypeScript since v4.0.0. For Vue 2 projects, users must install the v3.x series. It offers various message types (info, success, error, warning, loading), supports custom icons, HTML content, and provides 7 distinct positioning options. It also allows for programmatic closing and setting global default options, differentiating itself through its explicit Vue 3 focus, modern composition API integration, and flexible content rendering, including VNode support, without significant external dependencies.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates setting up a basic Vue 3 application, installing `vue-m-message` as a plugin with global default options, importing its styles, and then programmatically displaying a rich, custom-styled info message using Vue's H function.

import { createApp, h } from 'vue';
import Message from 'vue-m-message';
import 'vue-m-message/dist/style.css';

const App = {
  setup() {
    const showRichMessage = () => {
      Message.info(() => h('div', [
        'Here is a ', 
        h('strong', 'rich content'),
        ' message for ',
        h('a', { href: 'https://github.com/mengdu/m-message', target: '_blank' }, 'Vue M Message'),
        ' plugin. It will stay open until manually closed.'
      ]), {
        title: 'Welcome to Vue M Message!',
        duration: -1, // -1 means it needs to be closed manually
        iconURL: 'https://avatars.githubusercontent.com/u/11366654?s=40&v=4', // Custom icon
        closable: true // Allow manual closing
      });
    };

    // Display a message shortly after the app mounts
    setTimeout(showRichMessage, 1000);

    return () => h('div', [
      h('h1', 'Vue M Message Quickstart'),
      h('p', 'Check the top-right corner for a message.'),
      h('button', { onClick: showRichMessage, style: { padding: '10px 20px', fontSize: '16px' } }, 'Show Message Again')
    ]);
  }
};

const app = createApp(App);

// Install the message plugin globally
app.use(Message, {
  name: '$mMessage', // Optional: customize the global property name
  defaultOptions: { 
    position: 'top-right', 
    zIndex: 2000 
  }
});

app.mount('#app');

view raw JSON →