import { onMounted, onUnmounted } from 'vue'
export function useVh() {
let timer: NodeJS.Timeout | null = null
const setVh = () => {
if (timer)
clearTimeout(timer)
timer = setTimeout(() => {
const vh = window.innerHeight * 0.01
document.documentElement.style.setProperty('--vh', `${vh}px`)
}, 100)
}
onMounted(() => {
setVh()
window.addEventListener('resize', setVh)
window.addEventListener('orientationchange', setVh)
})
onUnmounted(() => {
window.removeEventListener('resize', setVh)
window.removeEventListener('orientationchange', setVh)
if (timer)
window.clearTimeout(timer)
})
}