I'm working on a responsive navigation menu, currently, i finished the mobile view, but i realize, i have a problem: for the desktop view, i want to hide the button that toggles the mobile navbar, and just show the navbar, but it doesn't show because the navbar is bound to a reactive variable with the "v-if" directive, my question is, how i'm gonna show the navbar? I thought setting the variable true or false depending on the screen size, but i cannot make a method because of the click event that also change the variable value to toggle the menu nav in mobile screens. What approach can i take? is it any way to remove the "v-if" on larger screens? Thank you for your help.
//reactive variable==========================
const showUserDropdown = ref(false)
//=================mobile toggle button=====================
<div class="pt-1 text-right">
<button class="text-right md:hidden" @click="showDropdown = !showDropdown">
<Icon :name="showDropdown ? 'up' : 'menu'" class="w-6 h-6 inline-block fill-cyan-800" />
</button>
</div>
//====================mobile nav==================
nav class="" v-if="showDropdown">
<ul class="">
<li v-for="(item, index) in menu" :key="item.id" class="pb-2">
<Link>
<Icon :name="item.icon_name" class="w-5 h-5 mr-2 inline fill-slate-500" />
<span class="capitalize"> </span>
</Link>
</li>
</ul>
</nav>
mobile: ======================== https://i.postimg.cc/3RCXGYX1/Screenshot-2023-03-13-at-14-23-42-Laravel.png
desktop: =============================
https://i.postimg.cc/TwXjhpDh/Screenshot-2023-03-13-at-14-24-03-Laravel.png
Via Active questions tagged javascript - Stack Overflow https://ift.tt/noNS1P7
Comments
Post a Comment