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>
相关推荐
Highcharts.js3 小时前
Highcharts漏斗图表使用配置指南
java·开发语言·javascript·信息可视化·highcharts·漏斗图
Decay__7 小时前
PostgreSQL 数据库全栈运维实战系列 — 合集索引(24 篇)
运维·数据库·sql·mysql·架构
科研邪修法7 小时前
PDF新增页面文字与文本批注怎么区分?以双版本培训讲义为例
前端·css·pdf
武昌库里写JAVA7 小时前
SpringBoot+Vue 项目介绍
java·javascript·git·sql·ai
Lanwarf-前端开发8 小时前
Vue3 + Canvas/WebGL 雷达扫描可视化实战:PPI、RHI、VOL、SVOL 四种模式原理与实现
前端·javascript·vue.js·webgl
FRing039 小时前
vue3干货总结2(vue3生命周期、父子通信、模版引用、provide和inject)
开发语言·前端·vue.js·vue3
锋行天下11 小时前
langgraph 全栈项目(三)
前端·人工智能·后端
YIAN11 小时前
从 LangChain 到 DeepAgents:手把手拆解 createAgent、Middleware 与复杂 Agent
javascript·langchain·deepseek
琳少_11 小时前
java程序开发笔记
java·开发语言·数据库·笔记
锋行天下11 小时前
langgraph 全栈项目(二)
前端·人工智能·后端