mpvue實(shí)現(xiàn)小程序?qū)Ш綑谙聞澗€及點(diǎn)擊滑動(dòng)

演示

演示.gif

<template>
  <div>
    <div class="nav">
      <div
        v-for="(item,index) in nav"
        :key="index"
        @click="tabClick(index)"
        :class="[{'active_item':activeIndex==index},'nav_item']"
      >{{item}}</div>
      <div
        :style="'width:'+(navWidth /2)+'rpx' + ';'+ 'transform:'+ 'translateX('+(activeIndex * navWidth+navWidth/4) + 'rpx'+')'"
        class="line"
      ></div>
    </div>
    <swiper
      :style="'height:'+  swiperHeight+'rpx'"
      class="swiper"
      duration="200"
      :current="activeIndex"
      @change="swiperChange"
    >
      <block v-for="(item,index) in nav" :key="index">
        <swiper-item>
          <scroll-view
            style="height:100%"
            scroll-y="true"
            lower-threshold="50"
            @scrolltolower="onReachBottom"
          >{{item}}</scroll-view>
        </swiper-item>
      </block>
    </swiper>
  </div>
</template>


<script>
export default {
  data() {
    return {
      nav: ["待審核", "通過(guò)", "拒絕"],
      activeIndex: 0,
      navWidth: 0,
      swiperHeight: 0
    };
  },
  methods: {
    //點(diǎn)擊導(dǎo)航欄
    tabClick(e) {
      this.activeIndex = e;
    },
    //swiper切換
    swiperChange(e) {
      this.activeIndex = e.mp.detail.current;
    }
  },
  onLoad() {
    let res = wx.getSystemInfoSync();
    this.navWidth = 750 / res.windowWidth * res.windowWidth / 3;  //此處獲取導(dǎo)航欄每一欄的寬度
    this.swiperHeight = 750 / res.windowWidth * res.windowHeight - 100;   //此處獲取除導(dǎo)航欄所剩下的swiper高度

  }
};
</script>



<style lang="less">
.nav {
  height: 100rpx;
  display: flex;
  // border: 1px solid black;
  position: relative;
  box-sizing: border-box;
  .nav_item {
    flex: 1;
    height: 100%;
    line-height: 100rpx;
    text-align: center;
  }
  .active_item {
    color: red;
  }
  .line {
    position: absolute;
    height: 6rpx;
    bottom: 0;
    background-color: red;
    transition: all 0.2s linear;
  }
}
.swiper {
}
</style>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容