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

遇到这个需求之前一直使用的小程序默认底部导航栏,且小程序默认入口页面为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"
    }
}

完结。

相关推荐
Q_Q5110082852 小时前
python+uniapp基于微信小程序的心理咨询信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
HuYi_code3 小时前
WeChat 小程序下载文件实现
微信小程序·uni-app
00后程序员张4 小时前
HTTPS 包 抓取与分析实战,从抓包到解密、故障定位与真机取证
网络协议·http·ios·小程序·https·uni-app·iphone
一匹电信狗4 小时前
【C++】C++风格的类型转换
服务器·开发语言·c++·leetcode·小程序·stl·visual studio
2501_915921434 小时前
iOS混淆与IPA加固实战手记,如何构建苹果应用防反编译体系
android·macos·ios·小程序·uni-app·cocoa·iphone
Q_Q5110082857 小时前
python+uniapp基于微信小程序的学院设备报修系统
spring boot·python·微信小程序·django·flask·uni-app
李慕婉学姐7 小时前
【开题答辩过程】以《自习室预约微信小程序》为例,不会开题答辩的可以进来看看
微信小程序·小程序
LB21127 小时前
苍穹外卖-购物车 前端修改(小程序主页与购物车模块显示不一致)
小程序
peachSoda77 小时前
自定义配置小程序tabbar逻辑思路
javascript·vue.js·微信小程序·小程序
ღ᭄ꦿ࿐Never say never꧂9 小时前
微信小程序 Button 组件 open-type 完全指南:从用户信息获取到客服分享的实战应用
spring boot·微信小程序·小程序·uni-app·vue3