• uniapp自定义权限菜单,动态tabbar


    已封装为组件,亲测4个菜单项目可以切换,

    以下为示例,根据Storage 中 userType 的 值,判断权限菜单

    1. <script>
    2. export default {
    3. props: {//当前页
    4. currentTab: {
    5. type: String,
    6. required: true
    7. }
    8. },
    9. data() {
    10. return {
    11. // 游客、管理员、村民
    12. usertype: uni.getStorageSync('userType'),
    13. }
    14. },
    15. computed: {
    16. // 权限菜单
    17. tabs() {
    18. if (this.usertype =='村民') {
    19. return [
    20. {
    21. "pagePath": "/pages/homepage/index",
    22. "iconPath": this.img('home-1'),
    23. "selectedIconPath": this.img('home'),
    24. "text": "首页"
    25. },
    26. {
    27. "pagePath": "/workPages/teach/index",
    28. "iconPath": this.img('bs-1'),
    29. "selectedIconPath": this.img('bs'),
    30. "text": "办事指南"
    31. },
    32. {
    33. "pagePath": "/pages/messag/index",
    34. "iconPath": this.img('mass-1'),
    35. "selectedIconPath": this.img('mass'),
    36. "text": "消息"
    37. },
    38. {
    39. "pagePath": "/pages/mine/index",
    40. "iconPath": this.img('mine-1'),
    41. "selectedIconPath": this.img('mine'),
    42. "text": "我的"
    43. }
    44. ],
    45. }else if (this.usertype =='管理员') {
    46. // 管理员
    47. return [
    48. {
    49. "pagePath": "/pages/homepage/index",
    50. "iconPath": this.img('home-1'),
    51. "selectedIconPath": this.img('home'),
    52. "text": "首页"
    53. },
    54. ],
    55. }
    56. }
    57. },
    58. methods: {
    59. switchTab(tab) {
    60. // console.log("底部导航", tab)
    61. let userType = uni.getStorageSync('userType')||this.userType
    62. let token = uni.getStorageSync('token')
    63. console.log('底部导航,用户,token|',tab.text ,userType,token)
    64. uni.navigateTo({
    65. url: tab.pagePath
    66. });
    67. },
    68. // 统一加图片域名路径
    69. img(img) {
    70. return 图片网址前缀 + 'tabBar/' + img + '.png'
    71. },
    72. },
    73. script>
    74. <style>
    75. .tab-bar {
    76. justify-content: space-around;
    77. align-items: center;
    78. height: 150upx;
    79. position: fixed;
    80. left: 0;
    81. z-index: 99999999999999999999;
    82. width: 100%;
    83. display: flex;
    84. justify-content: space-around;
    85. background: rgb(240 242 245 / 97%);
    86. border-top: 0.5px solid rgba(240, 242, 245, 1)
    87. }
    88. .tab-bar .tabli {
    89. flex: 1;
    90. display: flex;
    91. flex-direction: column;
    92. align-items: center;
    93. justify-content: center;
    94. }
    95. .tab-bar image {
    96. width: 25px;
    97. height: 25px;
    98. }
    99. .tab-bar text {
    100. font-size: 12px;
    101. margin-top: 5px;
    102. }
    103. .tab-bar text.active {
    104. font-weight: bold;
    105. }
    106. style>

    声明为全局组件:main.js 中添加

    1. import tzTabBar from "@/components/atz-tabbar/atz-tabbar.vue"//自定义底部菜单
    2. Vue.component('tzTabBar', tzTabBar)

    在页面中使用:

    "'消息'">

  • 相关阅读:
    LAMP平台搭建
    深入理解联邦学习——联邦学习与现有理论的区别与联系
    科研笔记:可用数据集整理(ing)
    java基本数据类型Char
    【SpringMVC】Controller中映射方法的参数解析过程
    Dapr中国社区活动之 分布式运行时开发者日 (2022.09.03)
    操作系统笔记(王道考研) 第三章:内存管理
    【Python模块】日期时间
    WSL 忘记ubuntu的密码
    C# Replace:一个熟悉而又陌生的替换
  • 原文地址:https://blog.csdn.net/qq_21113235/article/details/134184479