mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(use): usePageVisibility
This commit is contained in:
parent
1607aa8ba7
commit
36b8748552
18
packages/vant-use/src/usePageVisibility/index.ts
Normal file
18
packages/vant-use/src/usePageVisibility/index.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { ref } from 'vue';
|
||||||
|
import { inBrowser } from '../shared';
|
||||||
|
import { useEventListener } from '../useEventListener';
|
||||||
|
|
||||||
|
export function usePageVisibility() {
|
||||||
|
const visibility = ref<VisibilityState>('visible');
|
||||||
|
|
||||||
|
const setVisibility = () => {
|
||||||
|
if (inBrowser) {
|
||||||
|
visibility.value = document.hidden ? 'hidden' : 'visible';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setVisibility();
|
||||||
|
useEventListener('visibilitychange', setVisibility);
|
||||||
|
|
||||||
|
return visibility;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user