Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

SweetAlert for Notifications

Premium
2 min read

Now when we create a new post or edit a post, there are no notifications about successful action. In this lesson, we will add a notification using sweetalert2.

sweet alert message


To add sweetalert notifications, we will use a package avil13/vue-sweetalert2. First, let's install it.

npm install -S vue-sweetalert2

Next, we need to import styles and import/use the plugin in the main app.js file.

resources/css/app.css:

@import 'sweetalert2/dist/sweetalert2.min.css';
 
@tailwind base;
@tailwind components;
@tailwind utilities;

resources/js/app.js:

import './bootstrap';
 
import { createApp } from 'vue'
import App from './layouts/App.vue'
 
import router from './routes/index'
import VueSweetalert2 from 'vue-sweetalert2';
 
createApp(App)
.use(router)
.use(VueSweetalert2)
.mount('#app')

Now we need to call sweetalert in the posts Composable, after a successful...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

J
jm ✓ Link copied!

I'm encountering this issue "[plugin:vite:import-analysis] Failed to resolve entry for package "vue-sweetalert2". The package may have incorrect main/module/exports specified in its package.json.". I've followed all the instructions given above but with no luck, the stated issue occurs from time to time.

M
mcpacific ✓ Link copied!

At first I didn't see the notification pop up and thought it wasn't working at all. Turns out that it is way at the bottom of the screen and not styled, so it doesn't look anything like the images in the lesson. After looking into the package I saw that they recommend adding import 'sweetalert2/dist/sweetalert2.min.css'; to app.js for Vue3. Works fine now.