微信小程序?qū)崿F(xiàn)首頁不顯示tabBar功能

一.解決方案
①只要將首頁index目錄不加入app.json中tabBar的list列表里就好了
②在app.json的pages里將index目錄位置放在第一個,也就是小程序剛進入的首頁位置
③通過wx.switchTab方法跳轉(zhuǎn)到具有tabBar功能的頁面,就可以啦

 wx.switchTab({url: '../home/home'})

二.demo演示
1.首頁index的wxml代碼如下

<view class="container">
  <view>
    <button class="gotoBtn" bindtap="gotoBtnView"> 跳轉(zhuǎn) </button> 
  </view>
</view>

首頁index的js代碼如下:

Page({
  data: {
  },
  //事件處理函數(shù)
  gotoBtnView: function() {
    wx.switchTab({
      url: '../home/home'
    })
  },
})

2.將index放首頁位置,將需要tabbar功能的頁面(home和myInfo)添加到list中
app.json代碼如下

{
  "pages": [
    "pages/index/index",
    "pages/home/home",
    "pages/myInfo/myInfo"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle": "black"
  },
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/home/home",
        "text": "home",
        "iconPath": "",
        "selectedIconPath": ""
      },
      {
        "pagePath": "pages/myInfo/myInfo",
        "text": "myInfo",
        "iconPath": "",
        "selectedIconPath": ""
      }
    ]
  },
  "sitemapLocation": "sitemap.json"
}

3.測試
1.首頁如下圖所示,沒有tabBar功能,點擊跳轉(zhuǎn)


index.png

2.跳轉(zhuǎn)后的home頁面(具有tabBar功能),可以使用tabBar切換頁面了


home.png

myInfo.png

成功?。?!
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容