UNPKG

@u3u/vue-hooks

Version:
19 lines (18 loc) 752 B
import { ref, computed, onMounted, onUnmounted } from '@vue/composition-api'; export default function useWindowSize() { var width = ref(window.innerWidth); var height = ref(window.innerHeight); var update = function () { width.value = window.innerWidth; height.value = window.innerHeight; }; var widthPixel = computed(function () { return width.value + "px"; }); var heightPixel = computed(function () { return height.value + "px"; }); onMounted(function () { window.addEventListener('resize', update); }); onUnmounted(function () { window.removeEventListener('resize', update); }); return { width: width, height: height, widthPixel: widthPixel, heightPixel: heightPixel }; }