With Vue.js I need to toggle a parent-div, but always show the child-div.
<div v-if="showparent" class="parent">
<div class="child">
Child should always be visible
</div>
</div>
As far as I know this is not possible with Vue.js. The v-if
directive removes all div's inside when showparent
is false.
Any ideas how to achieve this?
Hiding a div hides all contained (child) divs. Move the parent out into a container div, do not nest the child div in it.
I have found two ways to do what you want to achieve, first one is to just repeat the child code in a v-else (not optimal because you need to repeat the code..) :
Or you can create a custom component:
And then use it like this