当前位置:网站首页>Applet custom native bottom navigation
Applet custom native bottom navigation
2022-04-22 06:43:00 【Bring in the red moon】
design sketch

app.json File add navigation
"custom": true, Open custom navigation
"tabBar": {
"custom": true,
"color": "#000000",
"selectedColor": "#000000",
"backgroundColor": "rgba(0,0,0,0)",
"list": [
{
"pagePath": "pages/index/index",
"text": " home page "
},
{
"pagePath": "pages/page1/page1",
"text": "page1"
},
{
"pagePath": "pages/page2/page2",
"text": "page2"
},
{
"pagePath": "pages/page3/page3",
"text": "page3"
},
{
"pagePath": "pages/page4/page4",
"text": "page4"
}
]
},
stay app.json Create a folder with the same level directory custom-tab-bar ( Folder location and name must be by custom-tab-bar )
Create under folder index.js index.json index.wxml index.wxss Four files The content is applet Custom component content My project structure image Inside the folder are the icons used

index.wxml file
<view class="tab-bar">
<image class="tab-bar-bg" src="./image/t_bg.png" mode="widthFix"></image>
<view class="tab-bar-list">
<view wx:for="{
{list}}" wx:key="index" class="tab-bar-item" data-path="{
{item.pagePath}}" data-index="{
{index}}" bindtap="switchTab">
<image class="tab-bar-item-image" src="{
{selected === index ? item.selectedIconPath : item.iconPath}}" mode="widthFix"></image>
<view class="tab-bar-item-text" style="color: {
{selected === index ? selectedColor : color}}">{
{item.text}}</view>
</view>
</view>
</view>
index.json file
{
"component": true
}
index.wxss file
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
z-index: 999;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-list {
width: 100%;
display: grid;
grid-template-columns: repeat(5, 1fr);
}
.tab-bar-item {
position: relative;
}
.tab-bar-item-image {
display: block;
margin: 0 auto;
width: 44rpx;
height: auto;
padding-top: 16rpx;
}
.tab-bar-item-text {
padding-top: 5rpx;
padding-bottom: 5rpx;
text-align: center;
font-size: 20rpx;
}
.tab-bar-item:nth-child(3) .tab-bar-item-image {
position: relative;
top: -44rpx;
left: 3rpx;
transform: scale(2);
}
.tab-bar-bg {
position: absolute;
left: 0;
top: 0;
width: 100%;
}
index.js file
Component({
data: {
selected: 0,
color: "#576271",
selectedColor: "#FF3800",
// The format and app.json Of tabBar Format corresponding
list: [{
pagePath: "/pages/index/index",
iconPath: "./image/t_01.png",
selectedIconPath: "./image/t_01_active.png",
text: " home page "
}, {
pagePath: "/pages/page1/page1",
iconPath: "./image/t_02.png",
selectedIconPath: "./image/t_02_active.png",
text: "page1"
}, {
pagePath: "/pages/page2/page2",
iconPath: "./image/t_03.png",
selectedIconPath: "./image/t_03.png",
text: "page2"
}, {
pagePath: "/pages/page3/page3",
iconPath: "./image/t_04.png",
selectedIconPath: "./image/t_04_active.png",
text: "page3"
}, {
pagePath: "/pages/page4/page4",
iconPath: "./image/t_05.png",
selectedIconPath: "./image/t_05_active.png",
text: "page4"
}]
},
attached() {},
methods: {
switchTab({
currentTarget
} = e) {
const data = currentTarget.dataset
const url = data.path
wx.switchTab({
url
})
this.setData({
selected: data.index
})
}
}
})
After the above is written Navigate to the corresponding page Add the following code
onShow() {
// Mark the selected icon corresponding to the current page
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 0 // This page corresponds to the subscript of custom bottom navigation
})
}
},
版权声明
本文为[Bring in the red moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220556230666.html
边栏推荐
- Uniapp custom bottom navigation bar H5 has an effective solution to invalid applet
- 从零开始学安卓(kotlin)三——BaseActivity、ActivityCollector
- MYSQL中,CAST函数的使用规则
- Introduction to postgreshub Chinese resource network
- Shumei technology has obtained the international certification of ISO / IEC 27701 privacy information management system
- MongoDB初接触——基础介绍篇
- Shumei technology was honored as the "top 100 scientific and technological innovation of private enterprises in Beijing"
- Open source database management systems are now more popular than commercial products
- The difference between watch and computed
- A series of interpretations of the general data protection regulations (gdpr): how to judge whether offshore enterprises are under the jurisdiction of gdpr?
猜你喜欢

一个三目表达式,引起的空指针

8张图让你一步步看清 async/await 和 promise 的执行顺序

LeetCode 1547:切棍子的最小成本

Shumei technology has obtained the international certification of ISO / IEC 27701 privacy information management system

Iframe子父级传参

创新实训(五)配置信息

在微信小程序中打开的页面不能超过10个,达到10个页面后,就不能再打开新的页面

点击触发其他dom元素:< $refs,$el >

Uniapp custom bottom navigation bar H5 has an effective solution to invalid applet

Pixel手机电信4G破解(含解锁BL和root)
随机推荐
Mysql 与Oracle使用
ArcGIS 纵断面分析
scala中的伴生类和伴生对象
The installation of redis is started and used by rookies (Windows)
The sixth anniversary of digital technology pays tribute to you behind it
正则验证
Using pgbackrest parallel archiving to solve wal stacking problem
APP更新
The digital risk control summit of digital America 2022 was opened, and the five highlights were exposed in advance
《信息系统项目管理师总结》第二章 项目范围管理
创新实训(五)中期检查
EXCEL 分列功能的使用
花费四天时间呕心沥血写了MySQL的全部笔记,很适合初学者的笔记。
瀑布流布局 js定位
uniapp解决首页点击返回(手机返回键)跳到登录页
Shumei technology was selected into the top 20 of Chaoyang high tech high growth in 2021
MySQL——索引
MYSQL 查看优化器后执行得SQL语句详情
创新实训(四)进度
Digital beauty technology won the "top ten intelligent risk control management innovation award" of the banker