import { onMounted,onBeforeUnmount,computed,ref } from "vue";

export default function useWindowSize() {
    const windowSize = ref(window.innerWidth)

    const nowWindowSize = () => {
        windowSize.value = window.innerWidth
    }

    onMounted(() => {
        window.addEventListener('resize',nowWindowSize)
    })

    onBeforeUnmount(() => {
        window.removeEventListener('resize',nowWindowSize)
    })

    const isMobile = computed(() => windowSize.value < 768)

    return {isMobile,windowSize}
}
