Connection checker for Nuxt3 ($nuxt.isOffline)

Viewed 137
1 Answers

Vue's ecosystem is more used with Composition API approach in mind nowadays, hence everything is a bit more decoupled overall.

VueUse's useOnline is de-facto the best approach overall.

Install it with yarn add @vueuse/core and you'll be able to use it right off

<script setup>
import { useOnline } from '@vueuse/core'

const online = useOnline()
</script>

<template>
  <p>Is my website online? {{ online }}</p>
</template>

Using Chrome, you can emulate an offline connection and see that the Boolean properly switches to false.

enter image description here


Credits to manniL on Discord as a reminder for that one, I totally forgot about useOnline().

Related