1. 程式人生 > >微信小程式底部導航Tabbar(轉)

微信小程式底部導航Tabbar(轉)

底部導航欄這個功能是非常常見的一個功能,基本上一個完成的app,都會存在一個導航欄,那麼微信小程式的導航欄該怎麼實現呢?經過無數的踩坑,終於實現了,好了,先看看效果圖。

對於底部導航欄,小程式上給出的文件要求裡面的item最少2個,最多五個。

好了,先看看程式碼:

在專案中找到這個檔案

 

複製程式碼
 1 {
 2   "pages":[
 3     "pages/index/index",
 4     "pages/logs/logs",
 5     "pages/mine/mine"
 6     
 7   ],
 8   "window":{
 9     "backgroundTextStyle":"light",
10     "navigationBarBackgroundColor": "#fff",
11     "navigationBarTitleText": "首頁",
12     "navigationBarTextStyle":"black"
13   },
14 
15   "tabBar": {  
16    "color": "#a9b7b7",  
17    "selectedColor": "#11cd6e",  
18    "borderStyle": "black" ,
19    "list": [{  
20      "selectedIconPath": "images/icon_consult_press.png",  
21      "iconPath": "images/icon_consult.png",  
22      "pagePath": "pages/index/index",  
23      "text": "首頁"  
24    }, {  
25      "selectedIconPath": "images/icon_invest_press.png",  
26      "iconPath": "images/icon_invest.png",  
27      "pagePath": "pages/logs/logs",  
28      "text": "一元投"  
29    },{  
30      "selectedIconPath": "images/icon_mine_press.png",  
31      "iconPath": "images/icon_mine.png",  
32      "pagePath": "pages/mine/mine",  
33      "text": "我的"  
34    }
35    ]  
36  } 
37 }
複製程式碼

這裡我先解釋一下這些屬性是什麼意思:

tabBar  指底部的 導航配置屬性

color  未選擇時 底部導航文字的顏色

selectedColor  選擇時 底部導航文字的顏色

borderStyle  底部導航邊框的樣色(注意 這裡如果沒有寫入樣式 會導致 導航框上邊框會出現預設的淺灰色線條)

list   導航配置陣列

selectedIconPath 選中時 圖示路徑

iconPath 未選擇時 圖示路徑

pagePath 頁面訪問地址

text  導航圖示下方文字

 

 

這裡需要注意一些小問題:

1、每個頁面的json檔案都不能去掉navigationBarTitleText這個屬性。否則會報錯

2、

 "pages":[
 3     "pages/index/index",
 4     "pages/logs/logs",
 5     "pages/mine/mine"
 6     
 7   ],
這個頁面的註冊一定要注意,第一個一定是要是最先顯示的,否則會出現底部導航看不到。