Subscribe on changes!

How to programmatically destroy a Vue3 component instance?

avatar
May 27th 2021

Version

3.1.0-beta.5

Reproduction link

https://codesandbox.io/s/zealous-monad-ixq87?file=/src/App.vue

Steps to reproduce

  1. Click on the button "Trigger toast' to trigger a toast
  2. Notice that the toast disappears after 2.5s
  3. 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?

avatar
May 27th 2021

setInterval is not tied to Vue component lifecycles, you need to clearInterval yourself in Alert's unmounted hook.

avatar
Mar 30th 2022

get the same problem, not about setInterval. i want to destroy a component been hidden. the component is unnecessary now.

avatar
Mar 30th 2022
image

same situation