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>
相关推荐
喝拿铁写前端14 分钟前
一套面向 Web、H5、小程序与 Flutter 的多端一致性技术方案
前端·架构
yaaakaaang19 分钟前
(一)前端,如此简单!---下载Nginx
前端·nginx
牛奶25 分钟前
为什么全国人民都能秒开同一个视频?
前端·http·cdn
KongHen021 小时前
uniapp-x实现自定义tabbar
前端·javascript·uni-app·unix
数据潜水员1 小时前
三层统计最小力度的四种方法
javascript·vue.js
汪子熙1 小时前
TS2320 错误的本质、触发场景与在 Angular / RxJS 项目中的系统化应对
前端·javascript·angular.js
我命由我123451 小时前
React - BrowserRouter 与 HashRouter、push 模式与 replace 模式、编程式导航、withRouter
开发语言·前端·javascript·react.js·前端框架·html·ecmascript
Younglina1 小时前
用AI全自动生成连环画?我试了,效果惊艳!
前端·ai编程·claude
Devin_chen1 小时前
ES6 Class 渐进式详解
前端·javascript
小番茄夫斯基1 小时前
前端开发的过程中,需要mock 数据,但是走的原来的接口,要怎么做
前端·javascript