Vue 导航 点击当前标题变色

1.效果

2.所有代码

<template>
    <div class="now-time">
      <div class="timebox">
      <a href="#" v-for="(item,index) in nowTime" v-on:click="addClass(index)"
         v-bind:class="{ bgColors:index==current}">
        <p>{{item.time}}</p>
        <p>{{item.start}}</p>
      </a>
      </div>
    </div>


</template>

<script>
    export default {
        name: "Nowtime",
      methods: {
        addClass:function(index){
          this.current=index;
        }
      },
      mounted() {

      },
      data(){
        return{
          current:0,
          nowTime:[
            {
              time:"9:00",
              start:"已开抢"
            },
            {
              time:"10:00",
              start:"已开抢"
            },
            {
              time:"11:00",
              start:"已开抢"
            },
            {
              time:"12:00",
              start:"已开抢"
            },
            {
              time:"13:00",
              start:"未开抢"
            },
            {
              time:"14:00",
              start:"未开抢"
            },
            {
              time:"15:00",
              start:"未开抢"
            },
          ],
        }
      }
    }
</script>

<style scoped>
.now-time{
  width: 100%;
  height: .8rem;
  background: #282832;
  display: flex;
  overflow-x:scroll;
}
.timebox{
  width: 100%;
  height: .8rem;
  display: flex;
  background: #282832;
}
  .now-time a{
    display: flex;
    flex-direction: column;
    width: 1.35rem;
    height: .79rem;
    align-items: center;
    flex-shrink: 0;
  }
.now-time a p:first-child{
  font-size: .23rem;
  color: white;
  font-weight: bold;
}
.now-time a p:last-child{
  font-size: .16rem;
  color: white;
}
.timebox .bgColors{
  background: #ff5700;
}
</style>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值