avil13 / vue-sweetalert2

A convenient wrapper for sweetalert2.
https://avil13.github.io/vue-sweetalert2/
656 stars 75 forks source link

this.$swal not work in VueJS 3 (script setup) #155

Closed quinhone closed 7 months ago

quinhone commented 8 months ago

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$swal')

authStore.login(values.email, values.password) .then( () => { router.push({ name: 'dashboard' }) }).catch( () => { this.$swal('Hello Vue world!!!'); })

avil13 commented 7 months ago

@quinhone Hi. The setup method doesn't have "this", so I recommend using a simple import, without using $swal. Also, I'd recommend looking for a different library.

quinhone commented 7 months ago

import Swal from 'sweetalert2'

Swal.fire( ) worked for me