实现的效果如下图
1、html
<view v-if="item.photo_list && item.photo_list.length !== 0" :class="getImageClass(item.photo_list.length)">
<view v-for="(j,ind) in item.photo_list" :key="'photo'+ind" class="image-wrapper">
<img :src="j" alt="" srcset="" @click="ClickImage(item.photo_list,j)" />
</view>
</view>
2、js
// 图片布局
getImageClass(total){
if (total === 4 ) {
return 'images';
}
return 'image';
},
3、css
.image {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
}
.image .image-wrapper {
margin: 5px;
width: calc(33% - 10px);
}
.images{
display: flex;
flex-wrap: wrap;
align-items: flex-start;
width: 70%;
}
.images .image-wrapper{
margin: 5px;
width: calc(50% - 10px);
}
.image-wrapper img {
width: 100%;
padding: 0;
margin: 0;
height: 206rpx;
object-fit: cover;
}