当前位置:   article > 正文

uniapp结合uView自定义tabbar_uniapp uview tabbar

uniapp uview tabbar

效果如下

5f13d071488648a2950d3865d617436b.png

 封装tabbar.vue        

  1. <template>
  2. <view class="tabbar">
  3. <u-tabbar style="color: red;" :value="currentTab" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true"
  4. zIndex='1000'>
  5. <u-tabbar-item text="首页" icon="home" name="index" @click="handTab(0)" />
  6. <u-tabbar-item text="放映厅" icon="photo" name='activity' />
  7. <u-tabbar-item text="直播" icon="play-right" name='community' />
  8. <u-tabbar-item text="消息" icon="chat" :badge="12" name="message" @click="handTab(3)" />
  9. <u-tabbar-item text="我的" icon="account" name="user" @click="handTab(4)" />
  10. </u-tabbar>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: "TabBar",
  16. props: {
  17. currentTab: {
  18. type: String,
  19. default: 'index'
  20. }
  21. },
  22. data() {
  23. return {
  24. switchTab: [
  25. "/pages/index/index",
  26. "/pages/activity/activity",
  27. "/pages/community/community",
  28. "/pages/message/message",
  29. "/pages/user/user"
  30. ]
  31. }
  32. },
  33. methods: {
  34. handTab(index) {
  35. uni.switchTab({
  36. url: this.switchTab[index]
  37. })
  38. }
  39. }
  40. }
  41. </script>

index.vue中引用

  1. <template>
  2. <view>
  3. <view>
  4. 主体内容
  5. <view>
  6. <tabbar currentTab='index' />
  7. </view>
  8. </template>
  9. <script>
  10. import tabbar from "@/components/tabbar.vue"
  11. export default {
  12. components: {
  13. tabbar,
  14. },
  15. }
  16. </script>

 pages.json 中配置 (注:可不配置tabBar当成普通页面进行使用也是可以的)

 

  1. "tabBar": {
  2. "custom": true,
  3. "list": [{
  4. "pagePath": "pages/index/index"
  5. }, {
  6. "pagePath": "pages/activity/activity"
  7. },
  8. {
  9. "pagePath": "pages/community/community"
  10. },
  11. {
  12. "pagePath": "pages/message/message"
  13. },
  14. {
  15. "pagePath": "pages/user/user"
  16. }
  17. ]
  18. }

注:app可能会导致原生tabbar占位问题,如下图所示

788ee94fb07245f086f0be75eaae8dba.png

 只需要在app.vue中添加以下代码即可隐藏原生tabbar

        onLaunch() {
            uni.hideTabBar()
        }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/251087
推荐阅读
相关标签
  

闽ICP备14008679号