行业知识
[uniapp]使用uview组件自定义tabbar
2026-12-03 14:24:43
来源:互联网转载
封装组件
在components���件夹里新增一个tabbar组件,需要注意tabbar之间的切换需要使用uni.switchTab,从非tabbar界面跳转到tabbar界面可以用uni.switchTab或者uni.reLaunch其他如navigateTo不能用于跳转tabbar界面.
export default {name: 'tabbar',props:['currentTab'],data() {return {switchTab: ["/pages/index/index","/pages/index/gcashOrder","/pages/index/my",]}},methods: {click1(e) {uni.switchTab({url: this.switchTab[e]})}}}.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}.tabbar-icon {width: 86rpx;height: 86rpx;background: #259C77;border-radius: 50%;display: flex;align-items: center;justify-content: center;} 组件调用
在需要用到tabbar的页面引入组件
如果是在app里用需要在调用页面里隐藏原生tabbar uni.hideTabBar()(在App.vue配置不生效不知道为什么)
配置文件
在page.json文件里新增tabbar配置文件
"tabBar": {"custom":true,"list": [{"pagePath": "pages/index/index"}, {"pagePath": "pages/index/gcashOrder"},{"pagePath": "pages/index/my"}]} 这样以后就可以使用了,效果如下