useListenNetwork
Introduction
监听当前网页是否在线执行回调
Basic Usage
ts
import { useListenNetwork } from '@flypeng/tool/browser';
Type Declaration
ts
/**
* 监听当前网页是否在线执行回调
* @param online
* @param offline
* @returns
*/
declare function useListenNetwork(online: (...args: any[]) => void, offline: (...args: any[]) => void): undefined;
Online Demo
useListenNetwork
<script lang="ts" setup>
import { useListenNetwork } from '@flypeng/tool/browser';
import { ref } from 'vue';
const isOnLine = ref(true);
useListenNetwork(
() => {
isOnLine.value = true;
},
() => {
isOnLine.value = false;
},
);
</script>
<template>
<div ref="online" v-if="isOnLine">网络已连接</div>
<div ref="offline" v-else>网络已断开</div>
</template>