DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Vue JS - Nav Class - hide nav option dependent on certain value

31 Views Asked by D Mawer At 15 March 2024 at 17:29 2025-12-23T01:41:09.541000

I have a number of menu items icons and dependent on an a variable wish to hide an option..

The code is:

<template>
  <main class="shell">
    <aside class="shell-nav">
      <nav class="nav-list">
        <ul>
          <li><router-link  to="xyz"><jam-grid/><span>xyz</span></router-link></li>
        </ul>
  

However, I'd like to add an extra route only if an admin condition is met...

<template>
  <main class="shell">
    <aside class="shell-nav">
      <nav class="nav-list">
        <ul>
          <li><router-link  to="xyz"><jam-grid/><span>xyz</span></router-link></li>

          <div v-if="isAdmin">
          <ul>
            <li><router-link to="settings"><jam-tools /><span>Settings</span></router-link></li>
          </ul>

        </ul>
      ...

How can I do this?

Thanks,

UPDATE:

My Nav class is below:

<template>
  <main class="shell">
    <aside class="shell-nav" :class="sidebarOpen ? 'open' : 'closed'">
      <div class="nav-trigger" @click="openSidebar()">
        <jam-menu v-if="!sidebarOpen" />
        <jam-arrow-left v-if="sidebarOpen" />
      </div>
      <nav class="nav-list">
        <ul>
          <li><router-link  to="xyz"><jam-grid/><span>xyz</span></router-link></li>         
          <li v-if="isAdminUser"><router-link to="settings"><jam-tools /><span>Settings</span></router-link></li>                                
        </ul>                             
      </nav>
      <button class="nav-help"><jam-help /></button>
    </aside>
    <div class="shell-container">
      <router-view></router-view>
    </div>
  </main>
</template>

<script>
import { RouterLink } from 'vue-router';

export default {
  data() {
    return {
      sidebarOpen: false,
    };
  },
  watch: {
    'this.$administrator': {
      handler: function (val) {
        console.log ("$administrator has changed: ", this.$administrator);
        vm.$forceUpdate();
      },
      deep: true,
    },   
    openSidebar: {
      handler: function (val) {
        console.log ("opensidebar changed: ", this.openSidebar);
        vm.$forceUpdate();
      },
      deep: true,
    },   
  },
  methods: {
    openSidebar() {
      console.log ("openSideBar");
      this.sidebarOpen = !this.sidebarOpen;
    },
    isAdmin()
    {
      var value = false;
      console.log ("isAdmin = ", value);
      if (this.$administrator > 0)
      {
          value = true;
      }
      value = false;
      return value;
    }
  },
  computed:
  {
     isAdminUser()
     {
      console.log ("isAdminUser: ", this.$administrator);
      this.$administrator;
     }
  },
 
};
</script>

I want to be able to do the following:

  1. If the this.$administrator value changes, update the nav-list straight away so the setting entry is shown if admin=true and not if admin=false
vue.js menu navigation
Original Q&A
0

There are 0 best solutions below

Related Questions in VUE.JS

  • Problems with matter.js and i18n in vue.js
  • Form Validation not working in custom component Vue
  • Authenticating vue app on each route change
  • Vue/TailwindCSS - Content is behind Sidebar
  • Vue3 Suspense Parent > Child Animation
  • Pass dynamic object data via nuxt-link to component
  • Failed to resolve import, but the path is valid, and detected as such by VSCode
  • how to use less variables in vue components?
  • Prevent a webpage from navigating away
  • Creating a modal window in product edit page in Shopware6 and saving data to custom table(repository) from a form within the modal window
  • How do I fix (or ignore) a TypeScript error that's inside a HTML template?
  • Vue.js Checkbox Alignment Issue: Centering Checkboxes Within Table Cells
  • How to reset vue product filter?
  • Vue display output of two dimensional array
  • vue js error when adding bonus items to another item

Related Questions in MENU

  • i want to create a drop down menu for blogger
  • Good practices for variables in Laravel's layout files
  • CSS - Change Margin of a Menu's Items..?
  • Data structure for a console menu in Node.js with nested options that can be navigated backwards
  • links on elementor modal not working on click
  • Accordion menu doesnt appear in frontpage
  • Detection of focus change events when `WM_KILLFOCUS` and `WM_SETFOCUS` do not arrive
  • How to automatically close mobile menu on scroll in website
  • burger-menu bug with react (flickering)
  • Menu and logo disappeared from the header in WordPress
  • {Solved} Menu items spread out when expanding the menu. WPF Application
  • Tkinter menu does not appear
  • Curved Carrousel
  • Not able to build menus in Wordpress
  • Astra Theme Mobile Menu Pushes Content Downward

Related Questions in NAVIGATION

  • Why might react-router navigate(-1) go back two routes/pages?
  • In @react-navigation's Tab.Navigator, I aim to lock the final screen while allowing the rest to scroll
  • (ros melodic) Lidar odometry is not working well
  • How to jump to a div using keyboard shortcuts?
  • Flutter: How to use a BottomSheet in a BottomNavigationBar?
  • Force security constraint managed 403 error when hitting restricted page with h:commandLink
  • In Entity Framework Core, how to populate self-referencing navigation collection without additional Include (using only entities already tracked)?
  • Blogger next previous navigations missing
  • Cannot achieve live navigation using js,openstreetmap and leaflet
  • Im using mapbox sdk navigation v2 and have a problem with the cycling view
  • Assigning sensor information to image coordinates
  • Blazor InteractiveServer navigate to external link whilst JWT added to the request headers?
  • Navigate to a different page from the side bar drawer without using the bottom navigation bar using persistent flutter package
  • WPF C# - Textblock inputs not saving on Navigation to new page?
  • React Chrome vs Firefox Navigation is not defined

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Pricesm.com
  • Aftereffectstemplates