uni-app 自定義底部導(dǎo)航欄的實現(xiàn)
這是我目前發(fā)現(xiàn)較好的uni-app 自定義底部導(dǎo)航欄方法,其他方法的缺點主要是在切換時,要么會閃爍,要么會每點擊一下,都會請求一次數(shù)據(jù)。如果有其他更好的方法,歡迎評論留言,最近才開始用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使用頻次較高,就設(shè)為全局變量了
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是為了關(guān)閉頁面切換動畫效果,
<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;
}
到此這篇關(guān)于uni-app 自定義底部導(dǎo)航欄的實現(xiàn)的文章就介紹到這了,更多相關(guān)uni-app 底部導(dǎo)航欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS獲取scrollHeight問題想到的標(biāo)準(zhǔn)問題
如果沒有文檔聲明可以用 document.body.scrollHeight,如果有文檔聲明必須用 document.documentElement.scrollHeight關(guān)于這方面的東西2007-05-05
Javascript 靜態(tài)頁面實現(xiàn)隨機顯示廣告的辦法
最近在做私服發(fā)布站時,客戶要求實現(xiàn)廣告隨機排序,而且要求在html頁面實現(xiàn),也就是說必須使用javascript來完成了。2010-11-11
javascript實現(xiàn)可改變滾動方向的無縫滾動實例
無縫滾動在制作一些圖片展示的時候還是蠻有用的,下面與大家分享下javascript實現(xiàn)的可改變滾動方向的無縫滾動,具體實現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06
Bootstrap Modal對話框如何在關(guān)閉時觸發(fā)事件
這篇文章主要為大家詳細(xì)介紹了Bootstrap Modal對話框如何在關(guān)閉時觸發(fā)事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12
解決iframe的frameborder在chrome/ff/ie下的差異
最近的項目中使用了動態(tài)創(chuàng)建iframe的js方法,發(fā)現(xiàn)iframe.frameborder="0"在IE7下不管用,而chrome/ff都正常的,很是郁悶。2010-08-08

