当前位置:网站首页>uni-app上自定义微信小程序的tabbar
uni-app上自定义微信小程序的tabbar
2022-07-26 23:07:00 【liuye066】
今天用uni-app开发微信小程序时,修改tabbar的样式无效,如selectedColor, iconWidth等,明明官网上都有这些属性,但在模拟器上就是没有效果。
自定义tabbar
1、在微信官网,自定义tabbar的页面,下载自定义tabbar示例代码;将其中的custom-tab-bar目录整个拷贝到项目根目录下;
2、修改custom-tab-bar/index.js的文件,路径都改为自己uni-app项目下的页面路径和图片路径
Component({
data: {
selected: 0,
color: "rgba(0,0,0,0.39)",
selectedColor: "rgba(0,0,0,0.93)",
list: [{
"pagePath": "/pages/index/index",
"iconPath": "/static/icon/11.png",
"selectedIconPath": "/static/icon/c11.png",
"text": "首页"
},
{
"pagePath": "/pages/goods/index2",
"text": "商品",
"iconPath": "/static/icon/22.png",
"selectedIconPath": "/static/icon/c22.png"
},
{
"pagePath": "/pages/shop/home",
"text": "门店",
"iconPath": "/static/icon/33.png",
"selectedIconPath": "/static/icon/c33.png"
},
{
"pagePath": "/pages/my/index",
"text": "我的",
"iconPath": "/static/icon/44.png",
"selectedIconPath": "/static/icon/c44.png"
}
]
},
attached() {
},
methods: {
switchTab(e) {
const data = e.currentTarget.dataset
const url = data.path
wx.switchTab({url})
this.setData({
selected: data.index
})
}
}
})3、pages.json文件tabbar配置:设置"custom": true
"tabBar": {
"custom":true,
"selectedColor": "rgba(0,0,0,0.93)",
"color": "rgba(0,0,0,0.39)",
"spacing": "4px",
"iconWidth": "24px",
"fontSize": "10px",
"height": "49px",
"list": [{
"pagePath": "pages/index/index",
"iconPath": "static/icon/11.png",
"selectedIconPath": "static/icon/c11.png",
"text": "首页"
},
{
"pagePath": "pages/goods/index2",
"text": "商品",
"iconPath": "static/icon/22.png",
"selectedIconPath": "static/icon/c22.png"
},
{
"pagePath": "pages/shop/home",
"text": "门店",
"iconPath": "static/icon/33.png",
"selectedIconPath": "static/icon/c33.png"
},
{
"pagePath": "pages/my/index",
"text": "我的",
"iconPath": "static/icon/44.png",
"selectedIconPath": "static/icon/c44.png"
}
]
}4、在main.js加入
// #ifdef MP-WEIXIN
Vue.mixin({
methods:{
setTabBarIndex(index) {
if (typeof this.$mp.page.getTabBar === 'function' &&
this.$mp.page.getTabBar()) {
this.$mp.page.getTabBar().setData({
selected: index
})
}
}
}
})
// #endif5、在各个tabbar页面中调用setTabBarIndex方法,例如:
首页pages/index/index中加入
onShow(e) {
// #ifdef MP-WEIXIN
this.setTabBarIndex(0);
// #endif
},然后在custom-tab-bar中修改相应的样式即可。
边栏推荐
- HCIP-第六天-OSPF静态大实验
- Guangguangzai's CSDN journey
- (title + detailed idea + annotated code) codeforces round 805 (Div. 3) F Equate Multisets
- 【斐波那契数列及螺线 基于C语言】
- 光光光仔的CSDN之旅
- Three handshakes and four disconnects of TCP
- Hcip bidirectional republication and routing strategy
- RIP路由信息协议-拓扑实验
- C language - array, string handler, strlen, strcpy and strncpy, strcat and strncat, StrCmp and strncmp
- Fist guessing applet based on Object-C novice on the road
猜你喜欢

HCIP-第二天

Sort the three integers from large to small (introduce various methods in detail)

C language student information management system can access text files based on arrays

膜拜,阿里内部都在强推的321页互联网创业核心技术pdf,真的跪了

【你了解Cache吗——全面理解高速缓冲存储器】

HCIP oSPF综合实验

祝大家七夕快乐,邀你源码共读

C语言 学生信息管理系统 基于数组 可以存取到文本文件

HCIP-第一天

Prompt to leave the page
随机推荐
Constant knowledge explanation of C language
静态路由综合实验
[Fibonacci sequence and spiral are based on C language]
[enchanting interpretation, 15 minutes let you thoroughly learn how to use the stack!!!]
【洋哥带你玩转线性表(四)——链式队列】
MySQL course 1. simple command line -- simple record welcome to supplement and correct errors
求解整数的每一位
How to judge whether a number is odd or even?
TCP的三次握手、四次断开
Record the nth SQL exception
离开页面的提示
Lvs+keepalived project practice
Hcip OSPF comprehensive experiment
Hcip the next day
【用C语言绘制谢尔宾斯基三角形】
【C语言】strlen与sizeof相关区分
猜拳小程序 基于Object-C 新手上路
HCIP-第二天
C language - array, string handler, strlen, strcpy and strncpy, strcat and strncat, StrCmp and strncmp
Hcip day 1