微信小程序tabbar底部導(dǎo)航
微信小程序重寫tabbar底部導(dǎo)航,供大家參考,具體內(nèi)容如下
1.app.js代碼如下:
editTabBar: function() {
var e = this.globalData.tabbar, a = getCurrentPages(), t = a[a.length - 1], s = t.__route__;
0 != s.indexOf("/") && (s = "/" + s);
for (var n in e.list) e.list[n].selected = !1, e.list[n].pagePath == s && (e.list[n].selected = !0);
t.setData({
tabbar: e
});
},
tabBar: {
color: "#123",
selectedColor: "#1ba9ba",
borderStyle: "#1ba9ba",
backgroundColor: "#fff",
list: [ {
pagePath: "/we7/pages/index/index",
iconPath: "/we7/resource/icon/home.png",
selectedIconPath: "/we7/resource/icon/homeselect.png",
text: "首頁(yè)"
}, {
pagePath: "/we7/pages/user/index/index",
iconPath: "/we7/resource/icon/user.png",
selectedIconPath: "/we7/resource/icon/userselect.png",
text: "我的"
} ]
},
globalData: {
userInfo: null,
tabbar: {
color: "#333",
selectedColor: "#d0501f",
backgroundColor: "#ffffff",
borderStyle: "#d5d5d5",
list: [ {
pagePath: "/pages/seller/gzt",
text: "工作臺(tái)",
iconPath: "/pages/images/gzt@3x.png",
selectedIconPath: "/pages/images/gztxz@3x.png",
selected: !0
}, {
pagePath: "/pages/seller/cp/cplb",
text: "商品",
iconPath: "/pages/images/dbdc.png",
selectedIconPath: "/pages/images/dbdcxz.png",
selected: !1
},
position: "bottom"
}
},
template.wxml
<template name="tabbar">
<view class="tabbar_box" style="background-color:{{tabbar.backgroundColor}}; border-top-color:{{tabbar.borderStyle}}; {{tabbar.position=='top'?'top:0':'bottom:0'}}">
<navigator class="tabbar_nav" openType="redirect" style="width:{{1/tabbar.list.length*100}}%; color:{{item.selected?tabbar.selectedColor:tabbar.color}}" url="{{item.pagePath}}" wx:for="{{tabbar.list}}" wx:key="index">
<image class="tabbar_icon" src="{{item.selected?item.selectedIconPath:item.iconPath}}"></image>
<text>{{item.text}}</text>
</navigator>
</view>
</template>
3.template.wxss
.tabbar_box {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-ms-flex-pack: distribute;
justify-content: space-around;
position: fixed;
bottom: 0;
left: 0;
z-index: 999;
width: 100%;
height: 100rpx;
border-top: 0.5rpx solid #d5d5d5;
}
.tabbar_nav {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
font-size: 25rpx;
height: 100%;
}
.tabbar_icon {
width: 40rpx;
height: 40rpx;
}
在需要用的頁(yè)面(wxml)添加如下代碼
<import src="template.wxml"></import>
<template is="tabbar" data="{{tabbar:tabbar}}"></template>
在需要的樣式(wxss)添加如下代碼
@import "template.wxss";
在需要的js頁(yè)面添加如下代碼:
var dsq, app = getApp();添加在頂部
tabbar: {},在data中添加
app.editTabBar();在onLoad中添加
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript獲取時(shí)區(qū)實(shí)現(xiàn)過程解析
這篇文章主要介紹了JavaScript獲取時(shí)區(qū)實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
Webpack4+Babel7+ES6兼容IE8的實(shí)現(xiàn)
這篇文章主要介紹了Webpack4+Babel7+ES6兼容IE8的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
基于Day.js更優(yōu)雅的處理JavaScript中的日期
Day.js它能夠幫助我們處理JavaScript中的日期,本文就詳細(xì)的介紹一下Day.js的具體使用,可以更簡(jiǎn)單的處理JavaScript中的日期和時(shí)間2021-09-09
javascript中函數(shù)作為參數(shù)調(diào)用的方法
這篇文章主要介紹了javascript中函數(shù)作為參數(shù)調(diào)用的方法,實(shí)例分析了函數(shù)作為操作調(diào)用的原理與相關(guān)技巧,需要的朋友可以參考下2015-02-02
解決一個(gè)微信號(hào)同時(shí)支持多個(gè)環(huán)境網(wǎng)頁(yè)授權(quán)問題
由于微信限制一個(gè)服務(wù)號(hào)只能配置一個(gè)網(wǎng)頁(yè)授權(quán)域名, 又不可能給每個(gè)環(huán)境單獨(dú)配一個(gè)服務(wù)號(hào),這樣不僅需要成本而且很浪費(fèi)資源,下面小編給大家?guī)?lái)了解決一個(gè)微信號(hào)同時(shí)支持多個(gè)環(huán)境網(wǎng)頁(yè)授權(quán)問題,感興趣的朋友一起看看吧2019-08-08
使用electron實(shí)現(xiàn)百度網(wǎng)盤懸浮窗口功能的示例代碼
這篇文章主要介紹了使用electron實(shí)現(xiàn)百度網(wǎng)盤懸浮窗口功能的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2018-10-10
JavaScript實(shí)現(xiàn)緩動(dòng)動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)緩動(dòng)動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11
select下拉框插件jquery.editable-select詳解
本篇文章主要介紹了select下拉框插件jquery.editable-select。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01

