判断浏览器是否联网
1、定义监听后事件
const alertOnlineStatus = () => {
window.alert(navigator.onLine ? 'online' : 'offline')
}
2、监听
window.addEventListener('online', alertOnlineStatus)
window.addEventListener('offline', alertOnlineStatus)
alertOnlineStatus()