vue写一个简单的头部导航样式切换

<template>
  <div class="tab-head">
    <ul class="tab-list">
      <li v-for="(item,index)  in tabList" v-on:click="addClass(index)" v-bind:class="{ active:index==current}">{{item.title}}</li>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tabList: [
        { id: 0, title: "首页1" },
        { id: 1, title: "首页2" },
        { id: 2, title: "首页3" }
      ],
      current:0
    };
  },
  methods: {
    addClass: function(index) {
      this.current = index;
    }
  }
};
</script>

style样式:

.tab-list{
  width: 100%;
  height: 45px;
  background: rgb(84, 92, 100);
  position: absolute;
  top: 0;
  left: 0;
}
.tab-list li{
  float: left;
  cursor: pointer;
  height: 41px;
  line-height: 45px;
  padding: 0 30px;
  color: #fff;
}
.tab-list li:hover{
  color: rgb(255, 208, 75);
  background: rgb(64, 74, 80);
  border-bottom: 4px solid rgb(64, 74, 80);
}
.tab-list li.active{
  border-bottom: 4px solid rgb(255, 208, 75);
}
.active{
  color: rgb(255, 208, 75);
  background: rgb(64, 74, 80)
}

用到的知识点,点击当前元素添加样式,点击其他元素移除兄弟元素的样式

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值