示例图:
nav{
width: 1080px;
height: 80px;
display: flex;
margin: 15px auto;
justify-content: space-between;
align-items: center;
}
nav .right{
width: 750px;
display: flex;
}
nav>.right>.aa{
width: 120px;
height: 80px;
line-height: 40px;
padding-top: 50px;
text-align: center;
margin-left: 5px;
border-bottom: 3px transparent solid;
position: relative;
}
nav .right>li:hover{
background-color: rgba(250, 235, 215, 0.559);
}
nav .right .subitem{
width: 120px;
display: none;
position: absolute;
top: 121px;
left: 0;
z-index: 1000;
color: red;
background-color: rgba(250, 235, 215, 0.559);
}
nav .right .subitem>li{
position: relative;
}
.subitem1{
width: 120px;
position: absolute;
top: 0;
left: 120px;
z-index: 1000;
color: red;
background-color: turquoise;
display: none;
}
nav .right>li:hover .subitem{
display: block;
}
/*这个代码是生成三角形的代码*/
.aaaa{
width: 0;
height: 0;
border-style: solid;
border-width: 6px;
border-color: transparent transparent transparent grey;
position: absolute;
right: 0;
top: 15px;
}
nav .right .subitem>li:hover .subitem1{
display: block;
}
数据数从后台渲染的 读者可自行在data里面写 也可自行生成
主要技术需要循环三次 当第三层的时候有的有 有的没有 在第三层里面判断是否存在元素(v-if)
<ul class="right">
<!-- @mouseenter='show(i)' :class="{light:i===active}"
@mouseleave='active=null' -->
<li v-for='(item,i) in list' class="aa">{{item.Name}}
<ul class="subitem">
<li v-for='item1 in item.Children' class="bb">
{{item1.Name}}
<ul class="subitem1">
<li v-for='item2 in item1.Children' v-if="item1.Children && item1.Children.length">
{{item1.Name}}j
</li>
</ul>
<div class="aaaa" v-if="item1.Children && item1.Children.length"></div>
</li>
</ul>
</li>
</ul>