vue中给v-for循环出来的元素分别加样式

vue中给v-for循环出来的元素分别加样式

1.绑动态样式`

    <div :class="box" v-for="(item, index) in datas" :key="index">
      <div class="da">
        <div class="box-typ">{{ item.name }}</div>
        <div class="one">{{ item.desc }}</div>
      </div>
      <div class="box-tex">{{ item.cash }}元</div>
    </div>

2.data中声明

  data() {
    return {
      datas: [],
    };
  },

3.最重要的一步,写css样式!!!!!
使用CSS3 :nth-child() 选择器:
使用公式 (an + b),表示周期的长度,n 是计数器(从 0 开始),b 是偏移值。

.box:nth-child(3n + 2) {
  border-radius: 5px;
  width: 350px;
  height: 117px;
  margin: 20px auto;
  /* background-color: pink; */
  background-image: linear-gradient(90deg, #fa7694 0%, #fdd34b 100%);
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.box:nth-child(3n + 3) {
  border-radius: 5px;
  width: 350px;
  height: 117px;
  margin: 20px auto;
  /* background-color: pink; */
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: linear-gradient(90deg, #09a9e8 0%, #28f0a0 99%);
}
.box:nth-child(3n + 4) {
  border-radius: 5px;
  width: 350px;
  height: 117px;
  margin: 20px auto;
  /* background-color: pink; */
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: linear-gradient(90deg, #e791f5 0%, #1bc9f6 99%);
}

成品6

还可以用三目或者v-if写,但是我觉得麻烦,,,用到的小伙伴给个三连啊!!!!!!!!!

posted @   喜欢Tb  阅读(137)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示