uniapp 使用 flex布局 将 图片展示 循环排列两列

将以下代码改成图片展示 循环排列两列 展示

html 复制代码
<template>
  <view>
    <image v-for="(image, index) in imageList" :key="index" :src="image"></image>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imageList: [
        'https://example.com/image1.jpg',
        'https://example.com/image2.jpg',
        'https://example.com/image3.jpg'
      ]
    };
  }
};
</script>

解决:

在下述代码中,我们给包含图片的容器设置了flex布局,并通过设置flex-wrap属性为wrap来实现换行。然后,给每个图片项设置了宽度为两列的一半,并设置了图片间距。这样就可以实现两列排列的图片展示效果。

html 复制代码
<template>
  <view class="image-container">
    <image v-for="(image, index) in imageList" :key="index" :src="image" class="image-item"></image>
  </view>
</template>

<style>
.image-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-top: 20rpx;
  margin-left: 20px;
  margin-right: 20px;
}

.image-item {
  width: 48%; /* 设置图片宽度为两列的一半 */
  margin-bottom: 10px; /* 设置图片间距 */
}
</style>

<script>
export default {
  data() {
    return {
      imageList: [
        '/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
		'/static/test-image.jpg',
      ]
    };
  }
};
</script>
相关推荐
互联网搬砖老肖9 分钟前
Web 架构之 CDN 加速原理与落地实践
前端·架构
会飞的鱼先生10 分钟前
javascript中Cookie、BOM、DOM的使用
前端·javascript·chrome
一棵树长得超出它自己14 分钟前
数据库系统学习
数据库
OpenTiny社区14 分钟前
开源之夏·西安电子科技大学站精彩回顾:OpenTiny开源技术下沉校园,点燃高校开发者技术热情
前端·开源
小袁搬码19 分钟前
PLSQLDeveloper配置OracleInstantClient连接Oracle数据库
数据库·oracle·pl/sqldeveloper
多多*22 分钟前
基于rpc框架Dubbo实现的微服务转发实战
java·开发语言·前端·redis·职场和发展·蓝桥杯·safari
灏瀚星空28 分钟前
用HTML5 Canvas打造交互式心形粒子动画:从基础到优化实战
前端·html·html5
Jackson__41 分钟前
聊一下HTTP 与 HTTPS 的区别,以及HTTPS 的加密方式
前端·面试
学习中的码虫43 分钟前
MySQL提升
数据库·mysql
一抓掉一大把1 小时前
MiniExcel模板填充Excel导出
开发语言·javascript·ecmascript