uni-app 自定義底部導航欄的實現
阿新 • • 發佈:2020-12-14
這是我目前發現較好的uni-app 自定義底部導航欄方法,其他方法的缺點主要是在切換時,要麼會閃爍,要麼會每點選一下,都會請求一次資料。如果有其他更好的方法,歡迎評論留言,最近才開始用uni-app寫專案,之前只是看了下文件。
1. tabbar 元件
<template> <view class="tabbar-container"> <view :style="{ color: currentIndex == index ? '#007EFF' : '#333333' }" v-for="(item,index) in tabbarList" :key="index" style="flex: 1" @click="switchTab(index)" > <view :class="'iconfont ' + item.icon" /> <view class="title">{{ item.title }}</view> </view> </view> </template> mounted(){ let dom = uni.createSelectorQuery().select('.tabbar-container') dom.boundingClientRect(e => { // tabbarHeight使用頻次較高,就設為全域性變量了 getApp().globalData.tabbarHeight = e.height }).exec() } <style scoped lang="scss"> .iconfont { font-size: 18px; } .tabbar-container { display: flex; justify-content: space-evenly; text-align: center; padding: 10px 0; background-color: #fff; box-shadow: 0 -1.5px 3px #eee; z-index: 999; .title { font-size: 12px; } } </style>
2. 引入
這裡使用的是swiper,duration為0是為了關閉頁面切換動畫效果,
<template> <view :style="'height: calc(100vh - ' + tabbarHeight + 'px)'"> <tab-bar :currentIndex="currentIndex" class="tabbar-container" @getCurrentIndex="getCurrentIndex" /> <swiper duration="0" disable-touch :current="currentIndex" style="height: 100%"> <swiper-item> <scroll-view scroll-y style="height: 100%"> <home /> </scroll-view> </swiper-item> <swiper-item> <todo-page /> </swiper-item> <swiper-item> <launch-task /> </swiper-item> <swiper-item> <my-page /> </swiper-item> </swiper> </view> </template> mounted() { this.tabbarHeight = getApp().globalData.tabbarHeight },getCurrentIndex(e) { this.currentIndex = e; }
到此這篇關於uni-app 自定義底部導航欄的實現的文章就介紹到這了,更多相關uni-app 底部導航欄內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!