← Back

netsells/no-dom-listeners warning

Prevent DOM listeners being manually added/removed using addEventListener/removeEventListener

Examples

❌  Incorrect

<template>
    <div>
    </div>
</template>

<script>
    export default {
        mounted() {
            document.addEventListener('click', this.onDocumentClick);
        },

        methods: {
            onDocumentClick() {
                // handle
            },
        },
    };
</script>

✅  Correct

<template>
    <div>
        <global-events
            @click="onDocumentClick"
        />
    </div>
</template>

<script>
    import GlobalEvents from 'vue-global-events';

    export default {
        components: {
            GlobalEvents,
        },

        methods: {
            onDocumentClick() {
                // handle
            },
        },
    };
</script>