UNPKG

@lui-ui/lui-vue

Version:

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

26 lines (25 loc) 728 B
import { onBeforeUnmount, onMounted, ref, watchEffect } from "vue"; import { isClient } from "../utils/isClient.mjs"; export function useOverflowWatcher(overflowVariable) { const overflowValue = ref(""); onMounted(() => { watchEffect(() => { if (isClient()) { const body = document.querySelector("body"); overflowValue.value = overflowVariable.value ? "hidden" : "auto"; if (body !== null) body.style.overflow = overflowValue.value; } else { overflowValue.value = "auto"; } }); }); onBeforeUnmount(() => { const body = document.querySelector("body"); if (body !== null) body.style.overflow = ""; }); return { overflowValue }; }