简体   繁体   中英

Show hide components in Vue.js 3

I have a navbar and a side bar (two separate components) and I'm trying to show/hide my sidebar using a button in the navbar component and it's not working, I tried:

  • v-show, v-if, using a localStorage value but nothing does it, the sidebar stays hidden.

Sidebar:

<template>
<aside v-show="local_variable" class="fixed hidden h-full top-0 left-0 flex lg:flex flex-shrink-0 flex-col w-64">

</aside>
</template>

Does the value saved in localStorage from the navbar needs to be updated on change when used with the sidebar?

Remove tailwind 'hidden' class if you want to toggle visibility of component with 'v-show', 'v-if'. Otherwise use Vue class and style binding https://vuejs.org/guide/essentials/class-and-style.html#binding-html-classes and remove 'v-show', 'v-if'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM