2.6.10
https://codesandbox.io/s/vue-template-n369v
create a component
and write the template structure like
<div>
<div class="test" v-if="flag">
<h2>first v-if</h2>
</div>
<div v-show="!flag">
<!-- any component that i want to render -->
<FullLifeCycle/>
</div>
<div v-if="flag">
<h2>second v-if</h2>
</div>
</div>
when using v-if, v-show, v-if together
and notice that the first element must give a class name
then, the component that in the v-show scope will be created twice (look my example console)
if i change the flag condition(i wrote that with a button), the component instance always recreates every times.
the component instance in v-show scope should be created once
when using v-if, v-show, v-if together
and notice that the first element must give a class name
then, the component that in the v-show scope will be created twice (look my example console)
I wrote all the component life cycle in v-show scoped.
the solutions
Duplicate of https://github.com/vuejs/vue/issues/10331
The workaround in this scenario is to set a key on the div in the middle with the v-show so it gets reused properly
Most helpful comment
Duplicate of https://github.com/vuejs/vue/issues/10331
The workaround in this scenario is to set a key on the
divin the middle with thev-showso it gets reused properly