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

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

完结。

相关推荐
一木 之林2 小时前
微信小程序开发全攻略·文章版|00 总览:74集学习路径与知识地图
人工智能·学习·计算机视觉·微信小程序·小程序
m0_587383005 小时前
无人自助拼豆系统的全栈开发方案
java·后端·struts·小程序·架构
AI源码5 小时前
雷山苗韵 - 非物质文化遗产传承平台
小程序·非遗小程序
CRMEB系统商城5 小时前
CRMEB开源商城系统(PHP)v8.0,打造全新AI二开商城底座!
开发语言·人工智能·小程序·开源·php
一木 之林5 小时前
微信小程序开发全攻略·文章版|01 入门与环境搭建
人工智能·学习·计算机视觉·微信小程序·notepad++
StevenLdh6 小时前
第八期 · 情绪闯关挑战盒:一个「无惩罚」成就系统的数据建模
java·微信小程序
眨眼猫会务智能体7 小时前
眨眼猫会务智能体会务系统的服务响应怎么样?出问题多久有人接?
安全·小程序·会务
微订校园外卖平台7 小时前
校园跑腿小程序上线:四端架构与校园外卖系统履约链路拆解
小程序·架构·外卖系统·本地生活·微订
拖孩8 小时前
AI 时代,个人开发者到底能不能靠一个小程序赚到钱
前端·后端·微信小程序