uni-app 自定義底部導航欄的實現(xiàn)
這是我目前發(fā)現(xiàn)較好的uni-app 自定義底部導航欄方法,其他方法的缺點主要是在切換時,要么會閃爍,要么會每點擊一下,都會請求一次數(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使用頻次較高,就設為全局變量了 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 自定義底部導航欄的實現(xiàn)的文章就介紹到這了,更多相關uni-app 底部導航欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
深入理解JavaScript和TypeScript中的class
class 聲明創(chuàng)建一個基于原型繼承的具有給定名稱的新類,下面這篇文章主要給大家介紹了關于JavaScript和TypeScript中class的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下。2018-04-04javascript實現(xiàn)文本框標簽驗證的實例代碼
這篇文章主要介紹了javascript實現(xiàn)文本框標簽驗證的實例代碼,需要的朋友可以參考下2018-10-10javascript實現(xiàn)根據(jù)漢字獲取簡拼
這里給大家分享一個JavaScript實現(xiàn)的根據(jù)漢字可以自動轉換簡拼代碼,有需要的朋友可以參考一下,并非本人原創(chuàng)來自網(wǎng)絡。2016-09-09