v-for循环中如何处理图片的渲染问题

DOM层代码:

 <div class="cardWrap">
        <div v-for="(item, index) in cardList" :key="index" class="cardItem">
          <i></i>
          <div class="label">
            <div class="name">{{ item.name }}</div>
            <div class="num">
              <em>{{ item.num }}</em>
              <span></span>
              <span>{{ item.state }}</span>
            </div>
          </div>
        </div>
      </div>

css代码:

  .cardWrap {
      margin-bottom: 23px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      > div {
        height: 72px;
        flex: 1;
        padding: 16px 13px;
        > i {
          width: 44px;
          height: 45px;
          display: inline-block;
        }
        span {
          font-size: 14px;
          font-family: SourceHanSansCN-Bold, SourceHanSansCN;
          font-weight: bold;
          color: #ffffff;
        }
        em {
          font-size: 24px;
          font-family: SourceHanSansCN-Bold, SourceHanSansCN;
          font-weight: bold;
          color: #ffffff;
        }
        &:not(:last-child) {
          margin-right: 20px;
        }
        @for $i from 1 through 5 {
          &:nth-child(#{$i}) {
            background: url('./newImg/card#{$i}.png') no-repeat;
            background-size: 100% 100%;
            > i {
              background: url('./newImg/cardIcon#{$i}.png') no-repeat;
              background-size: 100% 100%;
            }
          }
        }
        .name {
          font-size: 16px;
          font-family: SourceHanSansCN-Bold, SourceHanSansCN;
          font-weight: bold;
          color: #ffffff;
        }
        .label {
          display: inline-block;
          margin-left: 13px;
          line-height: 24px;
        }
        .num {
          margin-left: 89px;
        }
      }
    }

在这里要注意图片的命名要以i为区别
在这里插入图片描述

 cardList: [
        {
          name: 'xxx',
          num: '2',
          state: '待审核'
        },
        {
          name: 'yyy',
          num: '2',
          state: '待审核'
        },
        {
          name: 'zzz',
          num: '2',
          state: '待审核'
        },
        {
          name: 'hhh',
          num: '2',
          state: '待审核'
        },
        {
          name: 'fff',
          num: '2',
          state: '待审核'
        }
      ],

效果如图所示:
在这里插入图片描述
只循环一组图片时dom层的写法:

  <ul>
        <li v-for="(item, index) in List" :key="index">
            <i :class="'iconBox' + (index + 1) "></i>
        </li>
      </ul>

css写法:

 @for $i from 1 through 2 {
        .iconBox#{$i} {
          background: url('../img/cardIcon#{$i}.png') no-repeat;
          background-size: 100% 100%;
        }
      }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值