uniapp底部自定义tabbar遇到的问题

用这个组件自定义tabbar 

源代码:

<template>  
  <view>  
        <view>首页</view>
        <custom-tab-bar :items="tabItems" :currentIndex="currentTab" @item-click="onTabClick"
        :color="color" :selectedColor="selectedColor"></custom-tab-bar>
  </view>  
</template>  

<script>  
import CustomTabBar from '@/uni_modules/niceui-tabBar/components/niceui-tabBar/niceui-tabBar.vue';  
import tabbar from '@/uni_modules/niceui-tabBar/common/tabbar.js'
export default {  
  components: {  
    CustomTabBar  
  },  
  data() {  
    return {  
        currentTab: 0, // 当前选中的tab索引  
        tabItems:tabbar.tabItems,
        color:tabbar.color,
        selectedColor:tabbar.selectedColor
    }
  },
  methods: {  
     onTabClick(index) { // 切换tab的函数,当选中某个tab时触发  
       //this.currentTab = index;  
       if(index!=this.currentTab){
            uni.redirectTo({
                url:this.tabItems[index].pagePath
            })
       }
     }  
   }  
};  
</script>
//pagePath以自己项目的实际路径为准,这里是为了代码聚合在一起
const tabbar = {
    "tabItems":[
        {
            "pagePath": "/uni_modules/niceui-tabBar/pages/index/index",
            "icon": '/static/images/tabbar/index.png', 
            "selectedIcon":'/static/images/tabbar/index-action.png', 
            "text": '首页',
        },
        {
            "pagePath": "/uni_modules/niceui-tabBar/pages/add/add",
            "icon": '/static/images/tabbar/add.png', 
            "selectedIcon":'/static/images/tabbar/add-action.png', 
            "text": '新建',
            "up":true
        },
        { 
            "pagePath": "/uni_modules/niceui-tabBar/pages/user/user",
            "icon": '/static/images/tabbar/me.png', 
            "selectedIcon":'/static/images/tabbar/me-action.png', 
            "text": '我的',
        }
    ],
    "color":"#333",
    "selectedColor":"green",
}
export default tabbar

跳转报错

解决:

问题是用的redirectTo跳转,redirectTo可以在当前页面跳转到指定的目标页面,当前页面会被关闭,并跳转到指定的目标页面。 

而我们是底部导航栏页面切换,应该用switchTab

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值