vue 数组数据为奇数,但是样式需要隔行换色(奇偶数据颜色保持一致)

113 篇文章 1 订阅

没有做处理的效果:

数组:

      attendeeSignFormVOList: [
        { name: "自定义名称1", data: "自定义数据1" },
        { name: "自定义名称2", data: "自定义数据2" },
        { name: "自定义名称3", data: "自定义数据3" },
      ],

html:

<!--     :class="
                      attendeeSignFormVOList.length % 2 != 0 &&
                      index == attendeeSignFormVOList.length - 1
                        ? 'ticket-custom-item-content-max'
                        : ''
                    "添加此代码判断数组数量为奇数行且为最后一个子项时添加 ticket-custom-item-content-max类名将宽度设置为100%-->         
     <!-- 自定义项 -->
              <div class="ticket-custom-item">
                <div class="flex-row-wrap">
                  <div
                    class="ticket-custom-item-content flex-start"
                    v-for="(item, index) in attendeeSignFormVOList"
                    :key="index"
                    :class="attendeeSignFormVOList.length%2!=0&&index==attendeeSignFormVOList.length-1?'ticket-custom-item-content-max':''" 
                  >
                    <div class="order-details-name">{{ item.name }}</div>
                    <div class="order-details-content">{{ item.data }}</div>
                  </div>
                </div>
              </div>

css:

.ticket-custom-item {
    width: 100%;
    background: #f7f9fc;
  }
  .ticket-custom-item {
    border-top: 0.04rem solid rgba(242, 243, 247, 1);
    margin-top: 0.2rem;
    padding: 0.2rem 0 0 0;
  }
  .ticket-custom-item-content {
    width: 50%;
    padding: 0.13rem 0;
    background: #ffffff;
    margin-bottom: 0.14rem;
  }
  .ticket-custom-item-content-max {
    width: 100% !important;
  }

效果图:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值