vue v-for展示元素分两栏 中间使用分割线

1.效果展示:

2.代码展示:

复制代码
<template>
  <div class="container">
    <div class="column" v-for="(item, index) in items" :key="index">
      <div class="item">{{ item }}</div>
      <div v-if="index % 2 !== 0" class="divider"></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']
    };
  }
};
</script>

<style scoped>
.container {
  display: flex;
  flex-wrap: wrap;

}

.column {
  flex: 0 0 50%; /* 每个元素占据50%的宽度 */
  max-width: 50%;
  padding: 10px;
  box-sizing: border-box;
  position: relative;
}

.item {
  background-color: #f0f0f0;
  padding: 20px;
  margin-bottom: 10px;
}

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px; /* 分割线的宽度 */
  background-color: #ccc; /* 分割线的颜色 */
  margin-left: -10px;
}
</style>
相关推荐
橙序员小站25 分钟前
Agent Skill 是什么?一文讲透 Agent Skill 的设计与实现
前端·后端
炫饭第一名3 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
王晓枫3 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
符方昊3 小时前
React 19 对比 React 16 新特性解析
前端·react.js
ssshooter3 小时前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?
前端
曲折3 小时前
Cesium-气象要素PNG色斑图叠加
前端·cesium
Forever7_4 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
不会敲代码14 小时前
前端组件化样式隔离实战:React CSS Modules、styled-components 与 Vue scoped 对比
css·vue.js·react.js
Angelial4 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
jiayu4 小时前
Angular学习笔记24:Angular 响应式表单 FormArray 与 FormGroup 相互嵌套
前端