janjhnsn / vue3-simple-alert

MIT License
10 stars 2 forks source link

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

Install

npm i vue3-simple-alert

Basic Usage

install plugin

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

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";

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.

Optional. Specifies the text to display in the alert box

Optional. Specifies title of the alert box

Optional. Specifies icon type.

Optional. Advanced options. Refer to sweetalert2 documentation.

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.

Optional. Specifies the text to display in the confirm box

Optional. Specifies title of the confirm box

Optional. Specifies icon type.

Optional. Advanced options. Refer to sweetalert2 documentation.

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.

Required. Specifies the text to display in the dialog box

Optional. The default input text

Optional. Specifies title of the confirm box

Optional. Specifies icon type.

Optional. Advanced options. Refer to sweetalert2 documentation.

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