win-vue
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.1 • Public • Published

win-vue

Components for adding event listeners to the window, document, and document.body in Vue.js.

Why?

For Options API users

While there are utilities like VueUse's useEventListener, they're not compatible with components using Vue's Options API. Even with setup(), these utilities cannot be used it references anything created in the Options API (e.g. methods).

Declarative syntax in the template

Listening to events on the window object is a common practice. However, doing this with window.addEventListener often leads to cluttered code, and cleaning it up may be forgotten. Being able to interact with the window object directly within the template by leveraging Vue’s event binding syntax will dramatically improve the readability of your code.

Install

npm install -D win-vue

Usage

<script setup>
import { Window } from 'win-vue'

const onResize = (event) => {
    console.log('resized', event)
}
</script>

<template>
    <Window @resize.passive="onResize" />
</template>

Package Sidebar

Install

npm i win-vue

Weekly Downloads

0

Version

1.0.0-alpha.1

License

MIT

Unpacked Size

6.54 kB

Total Files

7

Last publish

Collaborators

  • hirokiosame