代码片段:
https://developers.weixin.qq.com/s/a9koVDmq7sDH
开发工具正常显示,但真机调试无法显示tabbar
1、开发者工具正常显示tabbar。
2、真机调试,无法显示自定义tabbar,底部为空白
3、system.js
userCheckRegister: function (openId, nickName, avatarUrl) {
wx.setStorageSync('roleId', '2');
// system页面 跳转至 用户主页home
wx.reLaunch({
url: '/pages/home/home?nickName=' + nickName + '&avatarUrl=' + avatarUrl + '&roleId=2',
});
},
4、home.js
data: {
roleId: "", //角色ID
}
onLoad: function (options) {
console.log(options.nickName);
console.log(options.avatarUrl);
console.log(options.roleId);
if(roleid){
this.setData({
roleId:options.roleId
})
}
},
onShow: function () {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 0
})
}
},
3、app.json
"pages": [
"pages/system/system",
"pages/home/home",
"pages/me/me",
"pages/selectEvaluateType/selectEvaluateType",
"pages/selectNewFileType/selectNewFileType",
.............
],
"window": {
"navigationStyle": "custom",
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black",
"backgroundColor": "#FFF"
},
"tabBar": {
"custom": true,
"color": "#999",
"selectedColor": "#3974F6",
"backgroundColor": "#fff",
"borderStyle": "white",
"list": [
{
"selectedIconPath": "resource/首页2.png",
"iconPath": "resource/首页.png",
"pagePath": "pages/home/home",
"text": "首页"
},
{
"selectedIconPath": "resource/新建档案2.png",
"iconPath": "resource/新建档案.png",
"pagePath": "pages/selectNewFileType/selectNewFileType",
"text": "新建档案"
},
{
"selectedIconPath": "resource/现场评价2.png",
"iconPath": "resource/现场评价.png",
"pagePath": "pages/selectEvaluateType/selectEvaluateType",
"text": "现场评价"
},
{
"selectedIconPath": "resource/我的2.png",
"iconPath": "resource/我的.png",
"pagePath": "pages/me/me",
"text": "我的"
}
]
},
4、custom-tab-bar ->index.js
Component({
data: {
selected: 0,
roleId: "",
color: "#999",
selectedColor: "#3974F6",
backgroundColor: "#fff",
borderStyle: "white",
allList: [{
list0: [
{
"selectedIconPath": "../resource/首页2.png",
"iconPath": "../resource/首页.png",
"pagePath": "../../pages/home/home",
"text": "首页"
},
{
"selectedIconPath": "../resource/新建档案2.png",
"iconPath": "../resource/新建档案.png",
"pagePath": "../../pages/selectNewFileType/selectNewFileType",
"text": "新建档案"
},
{
"selectedIconPath": "../resource/现场评价2.png",
"iconPath": "../resource/现场评价.png",
"pagePath": "../../pages/selectEvaluateType/selectEvaluateType",
"text": "现场评价"
},
{
"selectedIconPath": "../resource/我的2.png",
"iconPath": "../resource/我的.png",
"pagePath": "../../pages/me/me",
"text": "我的"
}
],
list1: [
{
"selectedIconPath": "../resource/首页2.png",
"iconPath": "../resource/首页.png",
"pagePath": "../../pages/home/home",
"text": "首页"
},
{
"selectedIconPath": "../resource/我的2.png",
"iconPath": "../resource/我的.png",
"pagePath": "../../pages/me/me",
"text": "我的"
}
],
}],
list: []
},
attached() {
console.log("custom tabbar roleId:", wx.getStorageSync('roleId'))
//根据用户角色,显示不同的底部导航栏
var roleId = wx.getStorageSync('roleId');
//管理员
if (roleId == "2") {
this.setData({
list: this.data.allList[0].list0
})
}
//商家
else if(roleId == "3"){
this.setData({
list: this.data.allList[0].list1
})
}
},
methods: {
switchTab(e) {
var index = e.currentTarget.dataset.index;
var url = e.currentTarget.dataset.path;
wx.switchTab({ url })
this.setData({
selected: index
})
}
},
})
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
代码片段:https://developers.weixin.qq.com/s/NclT4Dms73Dk