Hello, I am still learning VueJS and need some help with my nested navigation. The categories go 3 levels deep, but I'm having trouble displaying the third level properly.
Here is the JSON data I'm working with:
return {
navList: [
{ id: 1, type: 'Item', url: "#", name: "About Us", target: '_blank' },
{ id: 2, type: 'Item',url: "#", name: "Story", target: '_blank' },
{ id: 3, type: 'Item',url: "#", name: "Price", target: '_blank' },
{
id: 4,
type: 'Item',
url: "#",
name: "Services",
target: '_blank',
children: [
{
url: "https://twitter.com/",
name: "Twitter",
target: "_blank",
child: [
{
url: "https://twitter.com/",
name: "Twitter",
target: "_blank",
},
{
url: "https://dribbble.com/",
name: "Dribbble",
target: "_blank"
},
{
url: "https://www.behance.net/",
name: "Behance",
target: "_blank"
},
],
},
{
url: "https://dribbble.com/",
name: "Dribbble",
target: "_blank"
},
]
},
]
};
Below is the code for my navigation that I'm using to try and display the sub-categories:
I'm attempting to access them through `item.children.child`, but it's not showing up as expected, instead, it just displays "Service". Please refer to the screenshot below for more clarity:
<template>
<nav class="navbar navbar-light navbar-expand-lg mainmenu">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">
<li v-for="item in navList" :key="item.id" class="dropdown">
<template v-if="item.children">
<a class="dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
:id="item.name"
:href="item.url"
:title="item.name"
@click="show = !show">{{ item.name }}
</a>
<ul class="dropdown-menu"
:class="{ show }"
:aria-labelledby="item.name">
<li class="dropdown-item" v-for="{ url, name, index, target } in item.children" :key="index" >
<a class="dropdown-toggle" role="button" aria-haspopup="true" aria-expanded="false"
:href="url"
:title="name"
:target="target"
:data-toggle="name">
{{ name }}
</a>
<ul class="dropdown-menu"
:aria-labelledby="name">
<template v-if="item.children.child">
<li class="dropdown-item" v-for="{ url, name, index, target } in item.children.child" :key="index" >
<a class="dropdown-toggle" role="button" aria-haspopup="true" aria-expanded="false"
:href="url"
:title="name"
:target="target"
:data-toggle="name">
{{ name }}
</a>
</li>
</template>
<template v-else>
<a class="nav-link"
:href="item.url"
:title="item.name"
:target="item.target"
>{{ item.name }}</a>
</template>
</ul>
</li>
</ul>
</template>
<template v-else>
<a class="nav-link"
:href="item.url"
:title="item.name"
:target="item.target"
>{{ item.name }}</a>
</template>
</li>
</ul>
</div>
</nav>
</template>
If you want a visual of what I'm experiencing, check out this screenshot.