vue 行内多重判断,状态使用枚举

113 篇文章 1 订阅

多个条件判断显示不同的class

          class="agenda-title-item"
          :class="[
            titleIdx == index ? 'titleActive' : '',
            $i18n.locale == 'en' ? 'agenda-title-item-en' : '',
          ]"
          v-for="(item, index) in $t('agendaTitle')"
          :key="index"
          @click="changeTab(index)"
        >
          {{ item }}
        </div>

判断class

html:

        <!-- swiperIndex return中声明的变量swiperIndex:1 -->
  <div
            class="pointerBox flex-end"
            :class="`${
              swiperIndex == 1
                ? 'pointerBoxBlue'
                : swiperIndex == 2
                ? 'pointerBoxRed'
                : swiperIndex == 3
                ? 'pointerBoxYellow'
                : ''
            }`"
          >
            <div class="registrationStatus flex-center">报名成功</div>
          </div>

css:

  .flex-end {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }  
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
  }  
.pointerBox {
    width: 175px;
    height: 60px;
    position: relative;
  }
  .pointerBoxBlue {
    background: linear-gradient(347deg, #0064ff 15%, #5ba8ff 100%);
  }
  .pointerBoxYellow {
    background: linear-gradient(347deg, #fcb733 15%, #fdd474 100%);
  }
  .pointerBoxRed {
    background: linear-gradient(347deg, #ee3236 15%, #f77d80 100%);
  }
  .pointerBox:after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 0;
    height: 0;
    border-left: 30px solid white;
    border-top: 30px solid transparent;
    border-bottom: 30px solid transparent;
  }
  .registrationStatus {
    width: 145px;
    font-size: 24px;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    color: #ffffff;
  }

文字判断:

三目运算符:

            <div class="registrationStatus flex-center">
              {{
                swiperIndex == 1
                  ? "报名成功"
                  : swiperIndex == 2
                  ? "报名失败"
                  : swiperIndex == 3
                  ? "报名审核中"
                  : ""
              }}
            </div>

枚举:

html:
    
 
            <el-table-column label="订单状态" width="100">
              <template slot-scope="scope">
                <span
                  :style="'color:' + orderStatusColor[scope.row.orderStatus]"
                >
                  {{ orderStatusVal[scope.row.orderStatus] }}
                </span>
              </template>
            </el-table-column>

js:
    
    return{
           orderStatusVal: {
        "-1": "已取消",
        "-2": "退款申请中",
        "-3": "已退款",
        "-4": "部分退款",
        0: "待支付",
        1: "已支付",
      },
      orderStatusColor: {
        "-1": "rgba(36,46,66,0.4)",
        "-2": "#FFAB4F",
        "-3": "#EE423D",
        "-4": "#EE423D",
        0: "#FFAB4F",
        1: "#04B935",
      },
     }

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值