vue-removed-hook-mixin

Adds a 'removed' hook to components, signalling removal from DOM
9,929
vue
Install
npm install vue-removed-hook-mixin
Latest Version:0.1.2
License:MIT
Last Updated:Dec 29, 2020
Links: npm
Maintainer: diachedelic

vue-removed-hook-mixin

Adds a removed hook to components, signalling $el's removal from the DOM.

Usage

// 1) Use the mixin in a single component.
import addRemovedHook from "vue-removed-hook-mixin";
export default {
    mixins: [addRemovedHook],

    // ...

    removed() {
        // this.$el is no longer a descendant of document.body.
    }
}

// 2) Apply the mixin to all components.
import addRemovedHook from "vue-removed-hook-mixin";
Vue.mixin(addRemovedHook);

Rationale

The built in destroyed hook is called before a component is fully transitioned out of view, which is a problem if destroying a non-Vue component changes how it looks. For instance, an interactive map, once destroyed, may remove all its tiles and becomes an unsightly grey box. Detecting the end of transitions is unreliable, so I opted to wait until the component's root element was removed from the DOM.

Discussion

License

MIT

Related Packages

vue

The progressive JavaScript framework for building modern web UI.

588,019,132 54,801
vue
@vueuse/shared
372,738,348 22,398
@vueuse/core

Collection of essential Vue Composition Utilities

367,188,523 22,398
@vitejs/plugin-vue

The official plugin for Vue SFC support in Vite.

333,357,380 686
eslint-plugin-vue

Official ESLint plugin for Vue.js

266,364,830 4,591

Version History

Version Released License
0.1.2 MIT
0.1.1 MIT
0.1.0 MIT
0.0.4 MIT
0.0.3 MIT