当前位置: 首页 > article >正文

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

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

<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来实现换行。然后,给每个图片项设置了宽度为两列的一半,并设置了图片间距。这样就可以实现两列排列的图片展示效果。

<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>


http://www.kler.cn/news/161382.html

相关文章:

  • 微信小程序中生命周期钩子函数
  • Python Tornado 框架的终极指南!
  • 交易历史记录20231207 记录
  • chatgpt用到哪些算法
  • 【android开发-14】android中fragment用法详细介绍
  • 简单实现Spring容器(二)
  • linux远程桌面管理工具(xrdp)、向日葵
  • UE4 双屏分辨率设置
  • 浅聊JAVA开发下环境部署与使用工具的安装与部署
  • yml配置文件获取数值不一致
  • ASP.NET Core 使用IIS调试出现505.24错误
  • electron调用dll问题总汇
  • 插件原理与开发
  • Tap虚拟网卡
  • 如何使用 Oracle SQL Developer 连接 pgvector
  • 【蓝桥杯选拔赛真题73】Scratch烟花特效 少儿编程scratch图形化编程 蓝桥杯创意编程选拔赛真题解析
  • Linux 线程——信号量
  • c++实验多态程序设计
  • Linux下安装Docker与Docker Compose
  • 数据库的索引
  • 3D模型格式转换工具HOOPS Exchange的典型应用场景介绍
  • 深入了解Java Period类,对时间段的精确控制
  • 理解js中原型链的封装继承多态
  • ky10 server x86在线安装ffmpeg
  • 在安全环境中使用虚拟化进行隔离——Armv8.4上的安全世界软件架构
  • Python插件 - 动态 简单账表 通过SQL存储过程输出列实现动态展示
  • Apache Hive(部署+SQL+FineBI构建展示)
  • 【Element】el-table组件使用summary-method属性设置表格底部固定两行并动态赋值
  • SCI常用的连接词
  • SpringBoot自动重启