@netsells/vue-dom-listeners

0.1.1 • Public • Published

npm version Build Status codecov

Vue DOM Listeners

Handle DOM events outside the current component without worrying about memory leaks. When the component is destroyed, the mixin will automatically remove the event listeners from the targets.

Installation

yarn add @netsells/vue-dom-listeners

Usage

This mixin adds addEventListener and removeEventListener methods to the component. These take the same arguments as the standard functions, except the first argument should be the event target, e.g.:

document.addEventListener(...args) -> this.addEventListener(document, ...args)

Example

import DomListeners from '@netsells/vue-dom-listeners';

export default {
    mixins: [DomListeners],

    mounted() {
        this.addEventListener(document, 'click', (e) => {
            // on clicking anywhere in document
        });
    },
};

Dependencies (0)

    Dev Dependencies (24)

    Package Sidebar

    Install

    npm i @netsells/vue-dom-listeners

    Weekly Downloads

    2

    Version

    0.1.1

    License

    ISC

    Unpacked Size

    22.2 kB

    Total Files

    19

    Last publish

    Collaborators

    • rebeccaanderton
    • samturrell
    • spamoom
    • jakub.gawron