I am creating my first nuxtjs project and am using the axios module as my HTTP client.
The Problem
Use the sweetalert2 plugin within the axios module's errorHandler.
nuxt.config.js
module.exports = {
modules: [
'@nuxtjs/axios'
],
axios: {
errorHandler (error) {
if (process.browser) {
const swal = require('sweetalert2')
swal({
title: 'Error',
text: 'Error',
confirmButtonColor: "#895CF2",
confirmButtonText: 'Zurück',
type: 'error'
}).then(function () {
window.history.back();
})
}
},
plugins: [
{ src: '~/plugins/sweetalert2', ssr: false }
],
build: {
vendor: ['axios', 'sweetalert2']
}
}
plugins/sweetalert2.js
import Vue from 'vue'
import swal from 'sweetalert2'
Vue.use(swal)
The errorHandler works without sweetalert and the sweetalert code works, as is in the frontend (pages/components).
I would be very thankful for any kind of help!