Just to clarify my intentions...
Whenever Menu 1
is clicked, its corresponding ul
should be displayed. Similarly, when Menu 2
is clicked, its associated ul
should be shown. This behavior extends to hiding the ul
if the same menu item is clicked again.
Could someone provide an example illustrating how I can achieve this?
Menu 1
Click = Toggle ul display
<ul>
<li v-for="(item,index) in menuData" :key="index">
<router-link :to="item.path" exact @click.stop="showMenu(index)">{{ item.name }}</router-link>
<ul v-if="item.children" v-show="selected === index">
<li v-for="(childItem,ChildIndex) in item.children" :key="ChildIndex">
<router-link :to="childItem.path">{{ childItem.name }}</router-link>
</li>
</ul>
</li>
</ul>
<script>
export default {
name: "App",
data() {
return {
openshow: false,
selected: null,
menuData: [{name: "Home", path: "/",}, {name: "About", path: "/about",}, {name: "Menu 1", path: "#", children: [{name: "Menu 1.1", path: "/menu/1/1",}, {name: "Menu 1.2", path: "/menu/1/2",}, {name: "Menu 1.3", path: "/menu/1/3",},],}, {name: "Menu 2", path: "#", children: [{name: "Menu 2.1", path: "/menu/2/1",}, {name: "Menu 2.2", path: "/menu/2/2",}, {name: "Menu 2.3", path: "/menu/2/3",},],}, {name: "Gallery", path: "/gallery",}, {name: "Contact", path: "/contact",},],
}
},
methods: {
showMenu(index) {
this.selected = (this.selected === index) ? null : index;
}
}
}
</script>