Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useNetwork.md
1---2category: Sensors3---45# useNetwork67Reactive [Network status](https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API). The Network Information API provides information about the system's connection in terms of general connection type (e.g., 'wifi', 'cellular', etc.). This can be used to select high definition content or low definition content based on the user's connection. The entire API consists of the addition of the NetworkInformation interface and a single property to the Navigator interface: Navigator.connection.89## Usage1011```ts12import { useNetwork } from '@vueuse/core'1314const { isOnline, offlineAt, downlink, downlinkMax, effectiveType, saveData, type } = useNetwork()1516console.log(isOnline.value)17```1819To use as an object, wrap it with `reactive()`2021```ts22import { useNetwork } from '@vueuse/core'23// ---cut---24import { reactive } from 'vue'2526const network = reactive(useNetwork())2728console.log(network.isOnline)29```3031## Component Usage3233```vue34<template>35<UseNetwork v-slot="{ isOnline, type }">36Is Online: {{ isOnline }}37Type: {{ type }}38</UseNetwork>39</template>40```4142## Type Declarations4344```ts45export interface UseNetworkOptions extends ConfigurableWindow {}46export type NetworkType =47| "bluetooth"48| "cellular"49| "ethernet"50| "none"51| "wifi"52| "wimax"53| "other"54| "unknown"55export type NetworkEffectiveType = "slow-2g" | "2g" | "3g" | "4g" | undefined56export interface NetworkState extends Supportable {57/**58* If the user is currently connected.59*/60isOnline: Readonly<ShallowRef<boolean>>61/**62* The time since the user was last connected.63*/64offlineAt: Readonly<ShallowRef<number | undefined>>65/**66* At this time, if the user is offline and reconnects67*/68onlineAt: Readonly<ShallowRef<number | undefined>>69/**70* The download speed in Mbps.71*/72downlink: Readonly<ShallowRef<number | undefined>>73/**74* The max reachable download speed in Mbps.75*/76downlinkMax: Readonly<ShallowRef<number | undefined>>77/**78* The detected effective speed type.79*/80effectiveType: Readonly<ShallowRef<NetworkEffectiveType | undefined>>81/**82* The estimated effective round-trip time of the current connection.83*/84rtt: Readonly<ShallowRef<number | undefined>>85/**86* If the user activated data saver mode.87*/88saveData: Readonly<ShallowRef<boolean | undefined>>89/**90* The detected connection/network type.91*/92type: Readonly<ShallowRef<NetworkType>>93}94export type UseNetworkReturn = Readonly<NetworkState>95/**96* Reactive Network status.97*98* @see https://vueuse.org/useNetwork99* @param options100*101* @__NO_SIDE_EFFECTS__102*/103export declare function useNetwork(104options?: UseNetworkOptions,105): UseNetworkReturn106```107