1.定义tabBar
app.json中添加tabBar信息,custom设为true
"tabBar": {
"custom": true,
"backgroundColor": "#f7f7f7",
"list": [
{
"pagePath": "pages/index/index",
"text": "邀请函"
},
{
"pagePath": "pages/address/address",
"text": "地址导航"
},
{
"pagePath": "pages/contact/contact",
"text": "联系我们"
}
]
},
2.更改tabBar
根目录下创建custom-tab-bar文件夹
--file index.wxml
这里icon字体图标的做法上一篇介绍过
微信小程序-字体图标
<view class="row bg-white justify-between custom-tab-bar" active="{{ active }}" active-color="#07c160">
<view class="column align-center {{selected === index ? 'color-primary' : 'color-black'}}"
wx:for="{{ list }}" wx:key="index" data-index="{{index}}" bindtap="onChange"
data-url="{{item.pagePath}}">
<icon class="iconfont {{ item.icon }}"></icon>
{{item.text}}
</view>
</view>
--file index.js
Component({
data: {
selected: 0,
"list": [
{
"pagePath": "/pages/index/index",
"text": "邀请函",
"icon": "icon-qingshu"
},
{
"pagePath": "/pages/address/address",
"icon": "icon-lvhang",
"text": "地址导航"
},
{
"pagePath": "/pages/contact/contact",
"icon": "icon-gezi",
"text": "联系我们"
}
]
},
methods: {
onChange(e) {
const data = e.currentTarget.dataset;
wx.switchTab({
url: data.url
});
},
init() {
const page = getCurrentPages().pop();
this.setData({
selected: this.data.list.findIndex(item => item.pagePath === `/${page.route}`)
});
}
}
})
其他页面需要加入如下
onShow() {
this.getTabBar().init();
}
自定义样式
.custom-tab-bar {
height: 50rpx;
padding: 30px 20px 50px 20px;
font-family: 'ZCOOL KuaiLe';
border-top-left-radius: 65% 40%;
border-top-right-radius: 65% 40%;
}
效果图