@u3u/vue-hooks
Version:
⚡️ Awesome Vue Hooks
22 lines (21 loc) • 934 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var composition_api_1 = require("@vue/composition-api");
function useWindowSize() {
var width = composition_api_1.ref(window.innerWidth);
var height = composition_api_1.ref(window.innerHeight);
var update = function () {
width.value = window.innerWidth;
height.value = window.innerHeight;
};
var widthPixel = composition_api_1.computed(function () { return width.value + "px"; });
var heightPixel = composition_api_1.computed(function () { return height.value + "px"; });
composition_api_1.onMounted(function () {
window.addEventListener('resize', update);
});
composition_api_1.onUnmounted(function () {
window.removeEventListener('resize', update);
});
return { width: width, height: height, widthPixel: widthPixel, heightPixel: heightPixel };
}
exports.default = useWindowSize;
;