How to programmatically destroy a Vue3 component instance?
Version
3.1.0-beta.5
Reproduction link
https://codesandbox.io/s/zealous-monad-ixq87?file=/src/App.vue
Steps to reproduce
- Click on the button "Trigger toast' to trigger a toast
- Notice that the toast disappears after 2.5s
- Open the Chrome console and notice that the Toast component instance is still pinging "Still breathing" every 1s even
What is expected?
I would except the Toast component instance to be destroyed after using below commands in the file alert.js lines 18-19
render(null, container); document.body.removeChild(container);
What is actually happening?
Toast component instance is still living
Perhaps I missed it but is there a view to programmatically destroy a Vue3 component instance?
setInterval
is not tied to Vue component lifecycles, you need to clearInterval
yourself in Alert's unmounted
hook.
get the same problem, not about setInterval. i want to destroy a component been hidden. the component is unnecessary now.