vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
46.86k stars 8.22k forks source link

[plugin]How can a plugin know app mount/unmount ? #4516

Closed agileago closed 1 month ago

agileago commented 3 years ago

What problem does this feature solve?

I want to clear some effect when app unmount. but I can't find the app api to do this. now i only hack rootProps to add onVnodeBeforeUnmount prop to achieve it. but i find vue2 has event dispatch

https://github.com/vuejs/vue-router/blob/dev/src/index.js#L98

What does the proposed API look like?

app maybe should expose some function to achieve it

LinusBorg commented 3 years ago

Your plugin can expose a bootstrapping function / mixin that can be added to the root component.

That would be the usual way so far. Personally I'm not a friend of further increasing the Plugin API surface.

yyx990803 commented 3 years ago

There's currently no API to do this. For now wrapping the app's unmount function would probably be the cleanest way to do it.

yyx990803 commented 3 years ago

I think an easy improvement is allowing a plugin function to return a "cleanup" callback.

agileago commented 3 years ago

I think an easy improvement is allowing a plugin function to return a "cleanup" callback.

yes. perfect design