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:
- 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