npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vant-element-notice

v1.1.5

Published

A unified dialog API for Vue 2 projects using Element UI or Vant UI

Readme

vant-element-notice

npm version license

中文 | English

A unified dialog API for seamlessly integrating Element UI and Vant UI dialog functionality in Vue 2 projects.

Features

  • Unified API interface: Use the same function call method regardless of whether you're using Element UI or Vant UI
  • Automatic framework detection: Automatically selects the corresponding implementation based on the UI framework imported in your project
  • Supports chaining and Promises: All dialog methods return Promises, supporting modern JavaScript asynchronous programming patterns
  • Flexible configuration: Can use simple strings or detailed configuration objects

Requirements

  • Vue 2.x
  • Element UI 2.x or Vant UI 2.x (or both)

Installation

# Install with npm
npm install vant-element-notice --save

# Or install with yarn
yarn add vant-element-notice

# You also need to install at least one of these UI frameworks
# Element UI
npm install element-ui@^2.0.0 --save

# Or Vant
npm install vant@^2.0.0 --save

Usage

Import and register the plugin in your Vue project:

import Vue from 'vue'
import App from './App.vue'

// Import Element UI or Vant UI (choose one)
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

// Or
// import Vant from 'vant'
// import 'vant/lib/index.css'
// Vue.use(Vant)

// Import vant-element-notice
import vantElementNotice from 'vant-element-notice'
Vue.use(vantElementNotice)

new Vue({
  render: h => h(App)
}).$mount('#app')

Specify UI Framework

By default, vant-element-notice automatically detects the UI framework used in your project (based on whether Vue.prototype.$ELEMENT exists). However, you can also explicitly specify which framework to use when registering the plugin:

// Use configuration options to specify UI framework
Vue.use(vantElementNotice, {
  // Explicitly specify the UI framework to use: 'element' or 'vant'
  framework: 'element', 
  
  // Optional: Enable or disable specific features
  features: {
    message: true,
    alert: true,
    confirm: true
  }
})

API Reference

Message Notification

Basic usage:

// Basic message
this.$utils.message('This is a message')

// With options
this.$utils.message({
  message: 'Operation successful',
  type: 'success',
  duration: 3000
})

// Shorthand methods
this.$utils.message.success('Success message')
this.$utils.message.warning('Warning message')
this.$utils.message.error('Error message')
this.$utils.message.info('Info message')

Advanced configuration:

this.$utils.message({
  message: 'This is a message',
  type: 'success',
  duration: 3000,        // Display duration in milliseconds
  showClose: true,       // Whether to show close button (Element UI only)
  center: true,          // Center the message (Element UI only)
  onClose: () => {       // Callback when closed
    console.log('Message closed')
  }
})

Alert Dialog

Basic usage:

// Basic alert
this.$utils.alert('This is an alert')

// With title
this.$utils.alert('Alert content', 'Alert Title')

// With custom confirm button text
this.$utils.alert('Alert content', 'Alert Title', 'I understand')

// Using Promise
this.$utils.alert('Operation completed')
  .then(() => {
    console.log('User confirmed the alert')
  })

Advanced configuration:

// With full options
this.$utils.alert({
  title: 'Custom Title',
  message: 'This is a custom alert content',
  confirmButtonText: 'Got it',
  type: 'warning',               // Type: success, warning, info, error (Element UI only)
  showClose: true,               // Whether to show close icon
  closeOnClickModal: false,      // Whether to close when clicking on the mask
  callback: (action) => {
    console.log(`Alert closed with action: ${action}`)
  }
})

Confirm Dialog

Basic usage:

// Basic confirm
this.$utils.confirm('Are you sure you want to proceed?')
  .then(() => {
    // User clicked confirm button
    this.$utils.message.success('Operation confirmed')
  })
  .catch(() => {
    // User clicked cancel button
    this.$utils.message.info('Operation cancelled')
  })

// With title
this.$utils.confirm('Are you sure you want to delete this item?', 'Delete Confirmation')

Advanced configuration:

// With full options
this.$utils.confirm({
  title: 'Delete Confirmation',
  message: 'This action will permanently delete the file. Continue?',
  confirmButtonText: 'Delete',
  cancelButtonText: 'Cancel',
  type: 'warning',              // Type: success, warning, info, error (Element UI only)
  showClose: true,              // Whether to show close icon
  closeOnClickModal: false,     // Whether to close when clicking on the mask
  showCancelButton: true        // Whether to show cancel button
})
  .then(() => {
    this.$utils.message.success('Deleted successfully')
  })
  .catch(() => {
    this.$utils.message.info('Delete cancelled')
  })

Framework Compatibility Table

This table shows the parameter mapping between the unified API and the native APIs of each UI framework:

Message Parameters Mapping

| Unified API Parameter | Element UI Parameter | Vant Parameter | Description | |--------------|----------------|-----------|------| | message | message | message | Message content | | type | type | special handling* | Message type: success, warning, error, info | | duration | duration | duration | Display duration (milliseconds) | | showClose | showClose | not supported | Whether to show close button | | center | center | not supported | Whether to center the message | | onClose | onClose | onClose | Callback when closed |

* In Vant, type mapping: success='success', warning='text', error='fail', info='text'

Alert Parameters Mapping

| Unified API Parameter | Element UI Parameter | Vant Parameter | Description | |--------------|----------------|-----------|------| | title | title | title | Dialog title | | message | message | message | Dialog content | | confirmButtonText | confirmButtonText | confirmButtonText | Confirm button text | | type | type | not supported | Dialog type (success/warning/info/error) | | showClose | showClose | not supported | Whether to show close icon | | closeOnClickModal | closeOnClickModal | closeOnClickOverlay | Close when clicking mask | | closeOnPressEscape | closeOnPressEscape | not supported | Close when pressing ESC | | callback | callback | via Promise | Callback when closed |

Confirm Parameters Mapping

| Unified API Parameter | Element UI Parameter | Vant Parameter | Description | |--------------|----------------|-----------|------| | title | title | title | Dialog title | | message | message | message | Dialog content | | confirmButtonText | confirmButtonText | confirmButtonText | Confirm button text | | cancelButtonText | cancelButtonText | cancelButtonText | Cancel button text | | type | type | not supported | Dialog type (success/warning/info/error) | | showClose | showClose | showCancelButton | Whether to show close icon | | showCancelButton | showCancelButton | showCancelButton | Whether to show cancel button | | closeOnClickModal | closeOnClickModal | closeOnClickOverlay | Close when clicking mask | | closeOnPressEscape | closeOnPressEscape | not supported | Close when pressing ESC |

Examples

For more examples and complete documentation, please see the demo examples.

API Documentation

For detailed API documentation, please refer to the API Documentation.

Developer Notes

  1. It's not recommended to use the native dialog methods of Element UI and Vant in the same project. Always use the methods provided by this tool for consistency.
  2. This library requires Vue 2.x and either Element UI 2.x or Vant 2.x (or both).

Developers

This project is actively being developed. Issues and contributions are welcome.

License

MIT