本代码实现的功能:可动态添加里面的任何一级别的代码(不固定级别)
html代码:
<div class="hx-bigListOne">
<div class="hx-bigLiOne" v-for="item in items" :key="item.id">
<h5 class="hx-OneTit" @click="toggle(item)">{{item.title}}</h5>
<div v-show="item.show" class="hx-bigListTwo">
<div class="hx-bigLiTwo" v-for="li in item.data" :key="li.id">
<div class="hx-smaD">
<div style="width:80px;height:80px"></div>
<span style="font-size:12px">{{li.text}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
js代码:
data: function() {
return {
items: [
{
title: “划伤类型”,
data: [
{ text: “this is a text” },
{ text: “this is a text” },
{ text: “this is a text” }
],
show: false
},
{
title: “磕伤类型”,
data: [
{ text: “this is a text” },
{ text: “this is a text” },
{ text: “this is a text” }
],
show: false
},
{
title: “其他类型”,
data: [
{ text: “this is a text” },
{ text: “this is a text” },
{ text: “this is a text” }
],
show: false
}
],
}}
methods: {
toggle(item) {
if(item.data.length!=0){
item.show = !item.show;
}else{
item.show = item.show;
}
},
}
css代码:
.hx-bigListOne {
margin-left: 30px;
}
.hx-bigLiOne {
margin: 0 30px 10px 0;
height: auto;
}
.hx-OneTit {
width: 150px;
height: 30px;
font-size: 20px;
line-height: 30px;
}
.hx-bigListTwo {
height: 110px;
}
.hx-bigLiTwo {
float: left;
}
.hx-smaD {
width: 110px;
margin: 10px 15px;
}
实现的效果: