Vue Js Sweetalert Modal Notification Example

Vue Js Sweetalert Modal Notification Example

In this post we will give you information about Vue Js Sweetalert Modal Notification Example. Hear we will give you detail about Vue Js Sweetalert Modal Notification ExampleAnd how to use it also give you demo for it if it is necessary.

In this tutorial, i will give you simple example of vue js sweet alert notification using sweetalert2 vue npm plugin. you can use sweet alert component notification in php laravel vue too.

You need to just follow few step to add sweetalert notification. you can also use confirm modal box with vue.

vue-sweetalert2 npm package will provide method to generate of sweet alert notifications like show, success, info, error, and register. you can also set icon with text as you want.

Step 1: Create Vue App

first we need to create vue cli app using bellow command:

vue create myApp

Step 2: Install vue-sweetalert2 Package

Here we need to install vue-sweetalert2 npm package that will allow to make http request.

npm install -S vue-sweetalert2

Also see:Laravel Vue JS Pagination Example with Demo

Step 3: Use vue-sweetalert2

We need to use vue-sweetalert2 package in main.js file of vue js app.

src/main.js

import Vue from 'vue'

import App from './App.vue'

import VueSweetalert2 from 'vue-sweetalert2';

Vue.config.productionTip = false

Vue.use(VueSweetalert2);

new Vue({

render: h => h(App),

}).$mount('#app')

Step 4: Updated HelloWorld Component

Here, we will create HelloWorld.vue component with following code.

src/components/HelloWorld.vue

<template>

<div >

<div >

<h1 style="font-family:ubuntu">Vue toastr notifications example - ItSolutionStuff.com</h1>

<button v-on:click="showAlert">Hello world</button>

<button v-on:click="showAlertConfirm">Confirm Me</button>

</div>

</div>

</template>

<script>

export default {

methods: {

showAlert(){

this.$swal('Hello Vue world!!!');

},

showAlertConfirm(){

this.$swal({

title: 'Are you sure?',

text: "You won't be able to revert this!",

type: 'warning',

showCancelButton: true,

confirmButtonColor: '#3085d6',

cancelButtonColor: '#d33',

confirmButtonText: 'Yes, delete it!'

}).then((result) => {

if (result.value) {

this.$swal(

'Deleted!',

'Your file has been deleted.',

'success'

)

}

});

}

}

}

</script>

Now you can run vue app by using following command:

Also see:Vue Axios Post Request Example

npm run serve

I hope it can help you…

Hope this code and post will helped you for implement Vue Js Sweetalert Modal Notification Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  18  =  27

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US