Vue+iview實現添加刪除類

<style>
    .tab-warp{
        border-bottom: solid 1px #e0e0e0;
        overflow: hidden;
        margin-top: 30px;
        position: relative;
        z-index: 1;
    }
    .tab-item{
        float: left;
        height: 34px;
        line-height: 32px;
        padding: 0 20px;
        border-radius: 3px 3px 0 0;
        position: relative;
        z-index: 4;
        border: solid 1px transparent;
        transition: border .5s, color .3s;
        cursor: pointer;
    }
    .tab-item.selected{
        border-color: #e0e0e0 #e0e0e0 transparent;
        color: #2d8cf0;
    }
</style>

<template>
        <div class="tab-warp">
             <div class="tab-item" :class="{selected:index == indexCur}" v-for="(item, index) in info.tabInfo"
@click="setCategory(item,index)">{{item.categoryName}} </div> </div> </template> <script> export default () { data(){ return { indexCur: 0 } },
          mathods:{
              setCategory (item,index) {
               this.indexCur = index;
         },
     }
     }
</script>

效果圖:
 
注:當 index == indexCur 時纔會添加selected類,template中有些內容是接口獲取來的可沒必要理會
相關文章
相關標籤/搜索