uniapp 小程序沉浸式導(dǎo)航

基于uniapp 開發(fā)小程序確實速度快一些,下面是實現(xiàn)簡易沉浸式導(dǎo)航組件

只包含基礎(chǔ)樣式,標(biāo)題插槽,返回按鈕等功能,如需要更精準控制膠囊位置等需配合getMenuButtonBoundingClientRect 方法再做優(yōu)化

效果展示


image.png
實現(xiàn)方法
<template>
  <!-- 自定義狀態(tài)欄 -->
  <view>
    <view class="statu-bar-area" :style="{height:statusBarStyle.height}"></view>
    <view class="nav-area">
      <view class="nav-left" hover-class="active-hover">
        <uni-icons type="back" size="26" @click="onBack" v-if="pages.length>1"></uni-icons>
      </view>
      <view class="nav-middle">
        <slot name="default"  >
          <!-- 測試導(dǎo)航內(nèi)容 -->
        </slot>
      </view>
      <view class="nav-right"></view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "custom-nav-bar",
    data() {
      return {
        windowInfo: {},
        pages: []
      };
    },
    computed: {
      statusBarStyle() {
        return {
          height: (this.windowInfo.statusBarHeight || 0) + 'px'
        }
      }
    },
    beforeMount() {
      this.windowInfo = uni.getWindowInfo()
      this.pages = getCurrentPages();
    },
    methods: {
      onBack() {
        uni.navigateBack()
      }
    }
  }
</script>

<style scoped lang="scss">
  .nav-area {
    height: 88rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #222222;

    .nav-left {
      width: 200rpx;
      display: flex;
      align-items: center;
      padding-left: 16rpx;
    }

    .nav-right {
      width: 200rpx;
    }

    .nav-middle {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 28rpx;
      align-items: center;
      justify-content: center;
      text-align: center;
    }
  }
</style>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

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