小程序自定义底部导航。。。干货。。。custom-tab-bar得使用原创
原创1、首先 app.json文件 找到 tabBar 添加 “custom”: true 打开自定义tabBar
2,在根目录下新建custom-tab-bar目录 新建index(Component组件)**必须是index命名
2.1 wxml 文件
{{item.text}}
2.2 wxss文件
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding-top: 20rpx;
background: white;
display: flex;
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-border {
background-color: rgba(0, 0, 0, 0.33);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 2rpx;
transform: scaleY(0.5);
}
.tab-bar-item {
flex: 1;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.tab-bar-item cover-image {
width: 54rpx;
height: 54rpx;
margin-bottom: 10rpx;
}
.tab-bar-item cover-view {
font-size: 20rpx;
}
2.3 js文件
Component({
data: {
selected: 0,
color: "#7A7E83",
selectedColor: "#cf000e",
"list": [
{
"pagePath": "/pages/index/index",
"text": "首页",
"iconPath": "/img/home.png",
"selectedIconPath": "/img/home_on.png"
},
{
"pagePath": "/pages/category/category",
"text": "分类",
"iconPath": "/img/sort.png",
"selectedIconPath": "/img/sort_on.png"
},
{
"pagePath": "/pages/shoppingcart/tabBarCart",
"text": "购物车",
"iconPath": "/img/cart.png",
"selectedIconPath": "/img/cart_on.png"
},
{
"pagePath": "/pages/mine/mine",
"text": "我的",
"iconPath": "/img/my.png",
"selectedIconPath": "/img/my_on.png"
}
]
},
onshow() {
console.log(onshow.....)
},
methods: {
switchTab(e) {
const data = e.currentTarget.dataset
console.log(data)
const url = data.path
wx.switchTab({ url })
console.log(e)
this.setData({
selected: data.index
})
}
}
})
2.4 json文件
{
"component": true
}
3.使用~
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
上一篇:git指令篇原创 下一篇:ts中接口和的使用和作用封装原创