Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read properties of null (reading 'jquery') #161

Open
nigelandamCvSU opened this issue Jun 20, 2024 · 0 comments
Labels

Comments

@nigelandamCvSU
Copy link

nigelandamCvSU commented Jun 20, 2024

I use this Vue Sweetalert 2 in my Laravel 11, Inertia JS, and Vue 3.

In my app.js I properly registered the sweetalert.

import VueSweetalert2 from 'vue-sweetalert2';
import 'sweetalert2/dist/sweetalert2.min.css';

let sweetAlertOptions = {
  customClass: {
    confirmButton: "btn bg-green-700 hover:bg-green-600 text-white m-1 px-5",
    cancelButton: "btn btn-secondary m-1 px-5"
  },
  reverseButtons: true,
  buttonsStyling: false
};

createInertiaApp({
  resolve: async name => {
    const pages = import.meta.glob('./Pages/**/*.vue')

    const page = await pages[`./Pages/${name}.vue`]()
    page.default.layout = page.default.layout || AuthenticatedLayout

    return page
  },
  setup({ el, App, props, plugin }) {
    const app = createApp({ render: () => h(App, props) })

    app.component('InertiaLink', Link)
    app.component('FontAwesomeIcon', FontAwesomeIcon)
    app.use(plugin)
      .use(ZiggyVue)
      .use(VueSweetalert2, sweetAlertOptions)
      .mount(el)
  },
})

So now, I'm utilizing it to flash messages from every response to my request on my Authenticated.vue

<script setup>
import Navbar from '@/Components/Navbar.vue'
import Sidebar from '@/Components/Sidebar.vue'
import { getCurrentInstance, computed, watch } from 'vue'
import { getAuthenticatedUser } from '@/helper.js'
import { usePage } from '@inertiajs/vue3'
import { debounce } from 'lodash'

const { $swal } = getCurrentInstance().appContext.config.globalProperties
const user = getAuthenticatedUser()

const flashMessage = computed(() => {
  const flash = usePage().props.flash
  return flash
})

watch(flashMessage, debounce((newVal) => {
  if (newVal) {
    $swal(newVal.title || 'Alert', newVal.message, newVal.variant)
  }
}, 300), { // Debounce after 1 second
  immediate: true, // Show initial flash message
})
</script>

However upon refreshing/entering the page. I'm getting this error, I tried onMounted and onUpdated before. I tried now the combination of computed and watch. It seems the case is still the same.

vue-sweetalert.mjs:1056 Uncaught TypeError: Cannot read properties of null (reading 'jquery')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant