微信小程序 不同角色进入不同页面、呈现不同底部导航栏

遇到这个需求之前一直使用的小程序默认底部导航栏,且小程序默认入口页面为pages/index/index,要使不同角色呈现不同底部导航栏,必须要在不同页面引用不同的自定义导航栏。本篇将结合分包(subPackages)展开以下三步叙述。

一、创建不同角色的页面

1、目录中创建分包personA、personB。

2、app.json补充分包配置。

二、创建不同角色的底部导航栏

1、在conponents目录下创建personA和personB的自定义导航栏组件。

2、填充导航栏内容。

html 复制代码
<!--components/tabBarA/tabBarA.wxml-->
<view class="bottom-fixed">
    <text>A的底部导航栏</text>
</view>

/* components/tabBarA/tabBarA.wxss */
.bottom-fixed{
    width: 100%;
    height: 200rpx; 
    position: fixed;
    bottom: 0;
    background-color: antiquewhite;
}
html 复制代码
<!--components/tabBarB/tabBarB.wxml-->
<view class="bottom-fixed">
    <text>B的底部导航栏</text>
</view>

/* components/tabBarB/tabBarB.wxss */
.bottom-fixed{
    width: 100%;
    height: 200rpx;
    position: fixed;
    bottom: 0;
    background-color:azure;
}

三、完善页面内容

1、完善pages/index/index页面,控制跳转到personA或者personB的页面。

javascript 复制代码
// index.js
Page({
    onShow(option){
        wx.reLaunch({
          url: '/personA/index/index',
        //   url: '/personB/index/index',
        })
    }
})

2、 完善personA的页面

html 复制代码
<!--personA/index/index.wxml-->
<text>personA的页面</text>

<tabBar></tabBar>


<!--personA/index/index.json-->
{
    "usingComponents": {
        "tabBar": "/components/tabBarA/tabBarA"
    }
}

3、完善personB的页面

html 复制代码
<!--personB/index/index.wxml-->
<text>personB的页面</text>

<tabBar></tabBar>


<!--personB/index/index.json-->
{
    "usingComponents": {
        "tabBar": "/components/tabBarB/tabBarB"
    }
}

完结。

相关推荐
Nueuis1 小时前
微信小程序前端面经
前端·微信小程序·小程序
轩1157 小时前
实现仿中国婚博会微信小程序
微信小程序·小程序
知否技术11 小时前
2025微信小程序开发实战教程(一)
前端·微信小程序
喝牛奶的小蜜蜂13 小时前
个人小程序:不懂后台,如何做数据交互
前端·微信小程序·小程序·云开发
2501_9189410514 小时前
旅游微信小程序制作指南
微信小程序·小程序·旅游
全职计算机毕业设计15 小时前
SpringBoot+Mysql实现的停车场收费小程序系统+文档
spring boot·mysql·小程序
邹荣乐15 小时前
微信小程序动态tabBar实现:基于自定义组件,灵活支持不同用户角色与超过5个tab自由组合
前端·微信小程序·uni-app
半兽先生19 小时前
uniapp微信小程序视频实时流+pc端预览方案
微信小程序·uni-app·音视频
KerwinChou_CN20 小时前
自由开发者计划 004:创建一个苹果手机长截屏小程序
图像处理·算法·智能手机·小程序
Uyker20 小时前
空间利用率提升90%!小程序侧边导航设计与高级交互实现
前端·微信小程序·小程序