I have very simple example. There are two divs each with v-if with same variable, one with true and one with false. There is component nested inside the each of the divs (same component).
What I see (from the console.log) is that even there is v-if, the component is not destroyed and created but rather reused.
Is this bug? feature? Because I was relying on them to be destroyed (the problem occur in some more complex component).
Thanks.
Html and javascript below, there is also jsfiddle https://jsfiddle.net/ekeydar/p64ewLd1/3/
This is the html:
<div id="app">
<button @click="show1=!show1">
Toggle
</button>
<div v-if="show1">
<my-comp title="comp1"/>
</div>
<div v-if="!show1">
<my-comp title="comp2"/>
</div>
</div>
This is the javascript:
Vue.component('my-comp', {
props: ['title'],
template: '<h1>{{title}}</h1>',
created: function() {
console.log('my-comp.created title='+ this.title);
},
destroyed: function() {
console.log('my-comp.destroyed title='+ this.title);
}
}),
new Vue({
el: '#app',
data: {
show1: true,
},
})