🗒️页面是否激活
// 字段名,有浏览器兼容性问题(这里先忽略)
if (typeof document.hidden !== "undefined") {
hidden = "hidden"
visibilityChange = "visibilitychange"
state = "visibilityState"
}
// 关键代码
document.addEventListener('visibilitychange', function() {
// 'hidden', 'visible'
$vm.tab_visibility = document['visibilityState']
if($vm.tab_visibility == 'visible'){
EventBus.$emit('pg_visible')
socketIO.revisible()
}else{
socketIO.rehide()
}
}, false)
window.addEventListener('online', () => {
EventBus.$emit('pg_visible')
})
Last updated