1、定义监听后事件
const alertOnlineStatus = () => {
window.alert(navigator.onLine ? 'online' : 'offline')
}
2、监听
window.addEventListener('online', alertOnlineStatus)
window.addEventListener('offline', alertOnlineStatus)
alertOnlineStatus()
1、定义监听后事件
const alertOnlineStatus = () => {
window.alert(navigator.onLine ? 'online' : 'offline')
}
2、监听
window.addEventListener('online', alertOnlineStatus)
window.addEventListener('offline', alertOnlineStatus)
alertOnlineStatus()