mirror of
https://github.com/creativetimofficial/vue-material-kit.git
synced 2025-07-09 07:04:23 +08:00
21 lines
672 B
JavaScript
21 lines
672 B
JavaScript
import { computed, onMounted, onUnmounted, ref } from "vue";
|
|
|
|
export function useWindowsWidth() {
|
|
let windowWidth = ref(window.innerWidth);
|
|
|
|
const onWidthChange = () => (windowWidth.value = window.innerWidth);
|
|
onMounted(() => window.addEventListener("resize", onWidthChange));
|
|
onUnmounted(() => window.removeEventListener("resize", onWidthChange));
|
|
|
|
const type = computed(() => {
|
|
if (windowWidth.value < 992) return "mobile";
|
|
if (windowWidth.value >= 992) return "desktop";
|
|
return null; // This is an unreachable line, simply to keep eslint happy.
|
|
});
|
|
|
|
let width = computed(() => {
|
|
return windowWidth.value;
|
|
});
|
|
return { width, type };
|
|
}
|