微信小程序底部導(dǎo)航欄的設(shè)置是在全局app.json文件中,我們需要在該文件中設(shè)置tabBar屬性兽间。(注意:在json文件中历葛,格式要為json格式,而且不能有多余的逗號嘀略,也不能有注釋)恤溶。
底部導(dǎo)航欄格式:
"tabBar": {
? ? ? ? ? ? "color": "#555",? ? ? ? ? ? ? ? ? ?//未選中時的字體顏色
? ? ? ? ? ? "selectedColor": "#fedb5a",????//選中時的字體顏色
? ? ? ? ? ? "backgroundColor": "#ffffff",? ? //底部導(dǎo)航欄背景色
????????????"list":[? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//導(dǎo)航欄列表(就是導(dǎo)航欄個數(shù),最少2個帜羊,最多5個)
????????????????????{
????????????????????????????"pagePath":"pages/index/index",? ? ? ?//跳轉(zhuǎn)路徑
????????????????????????????"text": "首頁",? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //導(dǎo)航名字
? ? ? ????????????????????? "iconPath": "images/home1.png",? ? ? ?//未選中該導(dǎo)航時的圖片路徑
? ????????????????????? ? ? "selectedIconPath": "images/home2.png"????//選中后該導(dǎo)航的圖片路徑
????????????????????{
????????????????????????????"pagePath":"pages/logs/logs",
????????????????????????????"text": "我的",
? ? ? ????????????????????? "iconPath": "images/home1.png",
? ? ? ????????????????????? "selectedIconPath": "images/home2.png"
????????????????????]
}
自定義導(dǎo)航欄:為什么使用自定義底部導(dǎo)航欄咒程?因?yàn)榍袚Q到tabBar頁面時,樣式不能自定義(比如購物車頁面為babBar頁面時讼育,我希望購物車右上角有數(shù)字顯示當(dāng)前購物車商品數(shù)量)帐姻,而且不能傳參,所以就需要自定義了奶段。
自定義導(dǎo)航欄方法:
1.需要在tabBar屬性中添加?"custom":true 饥瓷。
在代碼根目錄下添加入口文件:
custom-tab-bar/index.js
custom-tab-bar/index.json
custom-tab-bar/index.wxml
custom-tab-bar/index.wxss
2.不需要添加"custom":true
"tabBar"屬性中,list列表只添加切換路徑痹籍,其余圖片路徑等等都不需要添加呢铆,然后使用我們的自定義組件即可。這種方法相對來說更加靈活蹲缠。