关于uniApp自定义配置的底部的tabBar配略解, 以及会遇到的bug若干

首先, 想要自定义tabBar 有两种方法, 可以自己去编写一个tabBar导航栏, 但是性能不会比原生高, 第二种, 使用 uni.setTabBarItem

image.png

这是配置项, 有两个注意点, pagePath的路径配置和pages.json有所不同, 需要加上代表绝对路径的 / 如下

image.png

,

index代表需要替换的tabBar数组位置, 其余配置一样, viseble 属性控制tabBar显示隐藏, 一般用来隐藏原配置中多余的tabbar

第一个小bug是使用该方法的时机, 这个方法只有在tabBar配置列的页面进行配置时才会生效, 也就是你跳转进入的第一个tabBar页面中进行你需要更换的选项, 也就是首页

image.png

注意, switchTab跳转的页面必须在pages.JSON 的tabBar list数组中有对应页面的配置项

最后是在跳转的首页(tabBar页面)中, 进行配置 调用uni.setTabBarItem 方法

image.png

 

js

复制代码

// arrToTab是一个简单的遍历函数 export const arrToTab = (arr) =>{ arr.forEach(it => { uni.setTabBarItem(it) }) }

效果图如下

image.png

 

image.png

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以使用uni-app提供的自定义组件和样式来实现悬浮底部tabbar。以下是一个简单的示例: 1. 创建一个自定义组件,例如命名为`custom-tabbar`。 2. 在`custom-tabbar`组件中,使用`fixed`定位和负的`bottom`值来实现悬浮在底部。 3. 在`custom-tabbar`组件中,添加tabbar的选项卡,并处理点击事件。 4. 在页面中引入`custom-tabbar`组件,并将选项卡的数据传递给组件。 下面是示例代码: ```vue <!-- custom-tabbar.vue --> <template> <view class="custom-tabbar"> <view class="tabbar-item" v-for="(item, index) in tabbarList" :key="index" @click="handleClick(index)"> <image :src="item.icon"></image> <text>{{ item.title }}</text> </view> </view> </template> <script> export default { data() { return { tabbarList: [ { title: '首页', icon: 'home' }, { title: '消息', icon: 'message' }, { title: '我的', icon: 'user' } ] }; }, methods: { handleClick(index) { // 处理点击事件 console.log('点击了第', index + 1, '个选项卡'); } } }; </script> <style> .custom-tabbar { position: fixed; bottom: -10px; /* 负的bottom值,使其悬浮在底部 */ width: 100%; height: 50px; background-color: #fff; box-shadow: 0px -2px 4px rgba(0, 0, 0, 0.1); display: flex; justify-content: space-around; align-items: center; } .tabbar-item { display: flex; flex-direction: column; align-items: center; } .tabbar-item image { width: 24px; height: 24px; } .tabbar-item text { font-size: 12px; margin-top: 6px; } </style> ``` 在页面中使用`custom-tabbar`组件: ```vue <!-- index.vue --> <template> <view> <!-- 页面内容 --> <view>内容</view> <!-- 引入自定义tabbar组件 --> <custom-tabbar></custom-tabbar> </view> </template> <script> import CustomTabbar from '@/components/custom-tabbar.vue'; export default { components: { CustomTabbar } }; </script> <style> /* 页面样式 */ </style> ``` 这样,你就可以实现一个自定义悬浮底部tabbar了。你可以根据自己的需求来修改`custom-tabbar`组件的样式和功能。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值