SoFunction
Updated on 2025-04-06

Achieve three-level menu effects

This article has shared the specific code for implementing the third-level menu for your reference. The specific content is as follows

html part

<div >
 <ul >
 <li class="firstLevel" v-for="(firstList,index) in menuData">{{}} 
  <ul v-if="">
  <li class="secondLevel" v-for="(secondList,index) in ">{{}}
   <ul class="thirdLevel">
   <li v-for="(thirdList,index) in secondList.value2">{{thirdList}}</li>
   </ul>
  </li>  
  </ul>
 </li>
 </ul>
</div>

js part

var app = new Vue({
 el:"#warp",
 data:{
 menuData: {
     firstList:{
     title:'Exercise Book 1', 
     value: [
      {
      title:"physics",
      value2:[
       "Summer",
       "winter vacation",
       "weekend"
      ]
      },
      {
      title:"Chemical",
      value2:[
      "Summer",
      "winter vacation",
      "weekend"
      ]
      },
     ],
   },
   secondList:{
    title:'Exercise Book 2', 
     value: [
      {
      title:"politics",
      value2:[
       "Summer",
       "winter vacation",
       "weekend"
      ]
    },
      {
      title:"geography",
      value2:[
      "Summer",
      "winter vacation",
      "weekend"
      ]
      },
     ],
   },
   thirdList:{
    title:'Exercise Book 3', 
     value: [
      {
      title:"Chinese",
      value2:[
       "Summer",
       "winter vacation",
       "weekend"
      ]
    },
      {
      title:"math",
      value2:[
       "Summer",
       "winter vacation",
       "weekend"
      ]
      },
      {
      title:"English",
      value2:[
       "Summer",
       "winter vacation",
       "weekend"
      ]
      },
     ],
   }
 },     
 },
});

CSS part

body{
 max-width: 640px;
 margin: 0px auto;
 font-size: 14px;
 color: #666666;
 background-color: #ffffff;
}
ul{
 padding: 0px;
}
li{
 list-style: none;
}
#menu{
 display: flex;
 justify-content: space-between;
}
.firstLevel{
 position: relative;
 min-width: 100px;
 cursor: pointer;
}
.secondLevel{
 display: none;
 margin-left: 10px;
}
.firstLevel:hover .secondLevel{
 display: block;
}
.thirdLevel{
 display: none;
 margin-left: 15px;
 width: 40px;
}
.secondLevel:hover .thirdLevel{
 display: block;
}

For more tutorials, click "Front-end component learning tutorial》, everyone is welcome to learn and read.

Regarding the tutorial on components, please click on the topicComponent learning tutorialCarry out learning.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.