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>
相关推荐
他是龙5512 分钟前
43:SQL注入进阶(请求类型、方法与格式实战)
数据库·sql
南山安4 分钟前
React学习:Vite+React 基础架构分析
javascript·react.js·面试
诺斯贝克4 分钟前
Unable to create converter for xxx.NetworkResponse<Auth> for method AuthService
前端·后端
listhi5204 分钟前
针对燃油运输和车辆调度问题的蚁群算法MATLAB实现
前端·算法·matlab
渔_6 分钟前
uni-app 页面传参总丢值?3 种方法稳如狗!
前端
快被玩坏了6 分钟前
二次封装了个复杂的el-table表格
前端
用户93816912553608 分钟前
在TypeScript中,可选属性(?)与null类型的区别
前端
JS_GGbond9 分钟前
JavaScript事件循环:餐厅里的“宏任务”与“微任务”
开发语言·javascript·ecmascript
eason_fan16 分钟前
Resize 事件导致的二进制内存泄漏:隐式闭包的 “隐形陷阱”
前端·性能优化
木卫二号Coding19 分钟前
affine+docker+postgresql+备份数据库
数据库·docker·容器