uni-app 动态隐藏TabBarItem指定项目


目前HBuilder X 版本: 2.9.8

官方的API中暂时没有对于TabBarItem的隐藏接口, 因此这里使用了折中的方法:

 

// H5平台生效,其他平台未知


// 获取TabBar所在的页面对象
const parentPage = this.$parent.$parent.$parent.$parent.$parent
const query = uni.createSelectorQuery().in(parentPage)
if (query) {
    // 此处定义你需要移除的第index + 1项TabBarItem
    let index = 1
    query.selectAll('.uni-tabbar > .uni-tabbar__item')._component.tabBar.list.splice(index, 1)
} else {
    console.info('%c INFO ', 'padding: 0 3px; color: #fff; border-radius: 3px; background-color: #409EFF;', '当前页面下不存在TabBar')
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM