vue实现tab切换并带切换样式的效果

如图所示

<template>
  <div class="home" @touchmove.prevent @mousewheel.prevent>
    <div class="header">
      <div class="header-one">
        <div></div>
      </div>
      <div class="header-two">
        <van-search
          clearable="true"
          shape="round"
          background="#ffff"
          maxlength="10"
          v-model="value"
          placeholder="请输入搜索关键词"
          input-align="center"
        />
      </div>
    </div>
    <div class="sec">
      <ul class="topnav-show" v-show="currindex==0">
        <li>内容1</li>
      </ul>
      <ul class="topnav-show" v-show="currindex==1">
        <li>内容2</li>
      </ul>
      <ul class="topnav-show" v-show="currindex==2">
        <li>内容3</li>
      </ul>
      <ul class="topnav-show" v-show="currindex==3">
        <li>内容4</li>
      </ul>
    </div>
    <div class="footer">
      <ul>
        <!-- vue实现tab切换并带切换样式的效果 -->
        <li v-for="(item,index) in tabList" :key="index" @click="btncli(index)">
          <P class="produc">
            <img :src="currindex==index ?item.img1 :item.img" alt />
          </P>
          <!-- <P :class="{text:!(index-currindex)}">{{item.name}}</P>
          这个也是切换的效果 -->
            <P :class="currindex==index?'text':''">{{item.name}}</P>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  name: "Home",
  data() {
    return {
      value: "", //这个是搜索的value值
      currindex: 0, //默认显示索引0
      tabList: [
        {
          name: "产品",
          img: require("../../src/assets/image/icon_product@3x(2).png"),
          img1: require("../../src/assets/image/icon_product@3x.png")
        },
        {
          name: "任务",
          img: require("../../src/assets/image/icon_product@3x(1).png"),
          img1: require("../../src/assets/image/icon_product@3x1(1).png")
        },
        {
          name: "问答",
          img: require("../../src/assets/image/icon_product@3x(2).png"),
          img1: require("../../src/assets/image/icon_product@33x.png")
        },
        {
          name: "我的",
          img: require("../../src/assets/image/icon_product@3x(3).png"),
          img1: require("../../src/assets/image/icon_product@32x.png")
        }
      ]
    };
  },
  methods: {
    // 点击切换tab
    btncli(index) {
      this.currindex = index;
    },
    onSearch(val) {
      Toast(val);
    },
    onCancel() {
      Toast("取消");
    }
  },
  components: {}
};
</script>
<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100vh;
  .header {
    width: 100%;
    height: 100px;
    line-height: 100px;
    vertical-align: middle;
    display: flex;
    /deep/.header-one {
      flex: 1.5;
      padding: 26px;
      vertical-align: middle;
      div {
        width: 100px;
        height: 50px;
        background: url("../assets/image/button_screen@3x.png") no-repeat center;
        background-size: cover;
        background-size: 100% 100%; //等比例拉伸
      }
    }
    .header-two {
      flex: 7;
      /deep/.van-search__content--round {
        border: 1px solid rgb(233, 229, 229);
      }
      /deep/.van-field__control {
        width: 70%;
      }
      /deep/.van-icon {
        font-size: 36px;
        line-height: 60px;
      }
      /deep/.van-search {
        width: 90%;
        height: 100px;
        .van-cell {
          background: none;
        }
        .van-cell__value {
          height: 60px;
          line-height: 60px;
          font-size: 26px;
          color: black !important;
        }
      }
    }
  }
  .sec {
    width: 100%;
    height: calc(100% - 210px);
    border: 1px solid red;
  }
  .footer {
    width: 100%;
    height: 110px;
    border: 1px solid red;
    ul {
      display: flex;
      line-height: 80px;
      font-size: 30px;
      color: #999999;
      justify-content: space-around;
      .text {
        color: #8dd966;
      }
      .produc {
        width: 60px;
        height: 50px;
        vertical-align: middle;
        margin-bottom: -16px;
        margin-top: 12px;
        border: 1px solid red;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值