How to unmount vuejs instance from DOM

Viewed 6206

Is there any way to unmount vuejs Instance from DOM? I want to mount and unmount the Vue instance for suited condition.

2 Answers

There is an vm.unmount() method on Vue 3 instance. If you are using Vue 2 you can use vm.$destroy().

If you are using file template you can use v-if condition on your component. That will remove element from DOM based on condition.

@gurkan-ugurlu third option works well.

My requirement was to mount and unmount the Vue instance. but it turns out, it was to render the DOM element for the suited condition for that template condition works well.

by searching, I understood that template conditions like if-else actually render the component. it's not like applying CSS property display: none;

Related