Simple alert(), confirm(), prompt() for Vue.js version 3, using sweetalert2.
Simple update of https://www.npmjs.com/package/vue-simple-alert to vue3
npm i vue3-simple-alert
// main.js
import { createApp } from "vue";
import VueSimpleAlert from "vue3-simple-alert";
const app = createApp({})
app.use(VueSimpleAlert);
// in any component
this.$alert("Hello Vue Simple Alert.");
// in any component
this.$confirm("Are you sure?").then(() => {
//do something...
});
// in any component
this.$prompt("Input your name").then(text => {
// do somthing with text
});
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 });
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.
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.
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.
This project is licensed under the MIT License - see the LICENSE file for details