效果如下图:
在这里插入图片描述

index.vue

<div class="test">
      <div class="testNav">
        <div
          :class="{'selected':tab === 1,'testTitle':true}"
          @click="changTab(1)"
        >人气</div>
        <div
          :class="{'selected':tab === 2,'testTitle':true}"
          @click="changTab(2)"
        >销量</div>
        <div
          :class="{'selected':tab === 3,'testTitle':true}"
          @click="changTab(3)"
        >综合</div>
      </div>
      <div class="container">
        <div v-if="tab===1">1</div>
        <div v-else-if="tab===2">2</div>
        <div v-else>3</div>
      </div>
    </div>

js

export default {
  data() {
    return {
      tab: 1
    };
  },
  methods: {
    changTab(index) {
      this.tab = index;
    }
  }
}

样式

.test {
    width: 100%;
    .testNav {
        padding: 0 20rpx;
        height: 80rpx;
        line-height: 80rpx;
        display: flex;
        .testTitle {
            flex: 1;
            text-align: center;
        }
        .selected {
            color: #87caee;
            border-bottom: 1px solid #87caee;
        }
    }
    .container {}
}
Logo

前往低代码交流专区

更多推荐