vue3-simple-alert-next
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Vue Simple Alert

version Vue.js version total downloads downloads license

Simple alert(), confirm(), prompt() for Vue.js version 3, using sweetalert2.

Origin project

Simple update of https://www.npmjs.com/package/vue-simple-alert to vue3

Features

  • Provides simple alert(), confirm(), prompt() like DOM Window methods.
  • Based on sweetalert2.
  • Installed as a Vue.js plugin.
  • Promise based API.
  • Support typescript.

Install

npm i vue3-simple-alert-next

Basic Usage

install plugin

// main.js
import { createApp } from "vue";
import VueSimpleAlert from "vue3-simple-alert-next";

const app = createApp({})

app.use(VueSimpleAlert);

Alert

// in any component

this.$alert("Hello Vue Simple Alert.");

Confirm

// in any component

this.$confirm("Are you sure?").then(() => {
  //do something...
});

Prompt

// in any component

this.$prompt("Input your name").then(text => {
  // do somthing with text
});

Advanced Usage

Global options

Global options can be set when initialize plugin. Refer to sweetalert2 documentation

// main.js
import { createApp } from "vue";
import VueSimpleAlert from "vue3-simple-alert-next";

const app = createApp({})

app.use(VueSimpleAlert, { reverseButtons: true });

API

alert(message?, title?, type?, options?)

The alert() method displays an alert box with a specified message and an OK button.

  • message: string

Optional. Specifies the text to display in the alert box

  • title: string

Optional. Specifies title of the alert box

  • type: 'success' | 'error' | 'warning' | 'info' | 'question'

Optional. Specifies icon type.

  • options: SweetAlertOptions

Optional. Advanced options. Refer to sweetalert2 documentation.

  • returns: Promise<boolean>

Will be resolved with true when alert box closed.

confirm(message?, title?, type?, options?)

The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.

  • message: string

Optional. Specifies the text to display in the confirm box

  • title: string

Optional. Specifies title of the confirm box

  • type: 'success' | 'error' | 'warning' | 'info' | 'question'

Optional. Specifies icon type.

  • options: SweetAlertOptions

Optional. Advanced options. Refer to sweetalert2 documentation.

  • returns: Promise<boolean>

Will be resolved when OK button clicked. If confirm box closed by any other reason, this promise will be rejected.

prompt(message, defaultText?, title?, type?, options?)

The prompt() method displays a dialog box that prompts the user for input.

  • message: string

Required. Specifies the text to display in the dialog box

  • defaultText: string

Optional. The default input text

  • title: string

Optional. Specifies title of the confirm box

  • type: 'success' | 'error' | 'warning' | 'info' | 'question'

Optional. Specifies icon type.

  • options: SweetAlertOptions

Optional. Advanced options. Refer to sweetalert2 documentation.

  • returns: Promise<string>

Will be resolved with input text when OK button clicked. If the user clicks OK without entering any text, promise will be resolved with an empty string. If dialog box closed by any other reason, this promise will be rejected.

License

This project is licensed under the MIT License - see the LICENSE file for details

Package Sidebar

Install

npm i vue3-simple-alert-next

Weekly Downloads

212

Version

1.0.2

License

MIT

Unpacked Size

14.7 kB

Total Files

6

Last publish

Collaborators

  • joshuaeasy