实现样式图:
<div class="tool-figure-note-box">
<div v-for="(figureNoteItem, figureNoteIndex) in list" :key="figureNoteIndex">
<template v-if="figureNoteItem.show">
<div class="figure-note-title">{{ figureNoteItem.title }}</div>
<div class="figure-note-list">
<div v-for="(item, index) in figureNoteItem.list" :key="index">
<el-image style="width: 20px" :src="item.src" />
<span class="margin-left-8">{{ item.text }}</span>
</div>
</div>
</template>
</div>
</div>
list: [
{
show: true,
title: '列表1:',
list: [
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题1'
},
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题2'
},
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题3'
},
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题4'
},
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题5'
}
]
},
{
show: true,
title: '列表2:',
list: [
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题1'
},
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题2'
},
{
src: require('@/assets/img/ic_map_region_3.svg'),
text: '标题3'
}
]
}
]
css主要是处理不同项之间的边距问题,因为,需要加margin或者padding,但是使用v-if不会去掉margin/padding,所以使用列表里面的title的加上padding来将两个列表之间撑开,列表中间有一条分割线,刚好可以用title的上border来做
.tool-figure-note-box {
width: 350px;
margin-top: 30px;
padding: 20px 30px;
border: 1px solid rgba(223,228,235,1);
border-radius: 8px;
> div {
&:first-of-type .figure-note-title{
padding-top: 0;
border-top: none; // 第一个去掉分割线
margin-top: 0;
}
.figure-note-title {
font-size: 16px;
color: #2A2F4D;
font-weight: 500;
padding-top: 15px;
border-top: 1px solid rgba(223,228,235,1); // 分割线
margin-top: 12px;
}
.figure-note-list {
display: flex;
flex-wrap: wrap;
> div {
display: flex;
align-items: center;
font-size: 14px;
color: #8392B7;
margin-top: 12px;
margin-right: 25px;
}
}
}
}