ItSolutionStuff.com

Vue Toastr Notifications Example Code

By Hardik Savani • November 5, 2023
Vue.JS

Our today's topic is how to implement toastr notifications in vue cli app. we will integrate toast notification using vue-toasted npm package.

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

we can easily use with laravel or any php framework, also with VueJS, Laravel, NuxtJS. bellow you can show step by step implementation of toast notification popup in vue js app from scratch.

Step 1: Create Vue App

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

vue create myApp

Step 2: Install vue-toasted Package

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

npm install vue-toasted --save

Step 3: Use vue-toasted

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

src/main.js

import Vue from 'vue'

import App from './App.vue'

import Toasted from 'vue-toasted';

Vue.config.productionTip = false

Vue.use(Toasted, {

duration: 1000

})

new Vue({

render: h => h(App),

}).$mount('#app')

Step 4: Update App.vue File

In this step, we need to update app.vue file, because i updated component so.

src/App.vue

<template>

<div id="app">

<Example></Example>

</div>

</template>

<script>

import Example from './components/Example.vue'

export default {

name: 'app',

components: {

Example

}

}

</script>

Step 5: Create Example Component

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

src/components/Example.vue

<template>

<div class="container">

<div class="large-12 medium-12 small-12 cell">

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

<button v-on:click="submitForm()">Trigger Notification</button>

</div>

</div>

</template>

<script>

export default {

data(){

return {

file: ''

}

},

methods: {

submitForm(){

this.$toasted.show('Hello, I am from ItSolutionStuff.com')

}

}

}

</script>

Now you can run vue app by using following command:

npm run serve

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Vue JS Get Selected Option Text Example

Read Now →

How to Use Ternary Operator in Vue JS?

Read Now →

How to Define Global Variables in Vue JS?

Read Now →

Vue JS Ajax Form Submit Example Code

Read Now →

How to Change Date Format using Moment in Vue JS?

Read Now →

File Upload using Vue js Axios PHP Example

Read Now →

How to Create and Use Component in Vue JS Cli?

Read Now →

Laravel Vue Router Example From Scratch

Read Now →

Laravel Vue JS File Upload Using Vue-dropzone Example

Read Now →

Laravel Vue JS Image Upload Example

Read Now →

Laravel Vue JS Axios Post Request Example

Read Now →

Laravel Vue JS Infinite Scroll Example with Demo

Read Now →

Laravel Vue JS Pagination Example with Demo

Read Now →