欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

小程序tabBar跳轉頁面并隱藏tabBar - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網站建設-昆明葵宇信息科技有限公司

159-8711-8523

云南網建設/小程序開發(fā)/軟件開發(fā)

知識

不管是網站,軟件還是小程序,都要直接或間接能為您產生價值,我們在追求其視覺表現(xiàn)的同時,更側重于功能的便捷,營銷的便利,運營的高效,讓網站成為營銷工具,讓軟件能切實提升企業(yè)內部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當前位置>首頁 » 新聞資訊 » 小程序相關 >

小程序tabBar跳轉頁面并隱藏tabBar

發(fā)表時間:2021-3-31

發(fā)布人:葵宇科技

瀏覽次數(shù):117

在開發(fā)小程序過程中,相信有一部分人,遇到過一個問題:當使用tabBar跳轉頁面時,所跳轉的頁面下方必定有 tabBar顯示,而當你需要把它隱藏時,卻束手無策。話不多說,在這里給大家分享如何隱藏tabBar的方法。

方法一:自定義tabBar

使用自定義tabBar,新建一個tarBar.wxml模板頁,然后引用模板的頁面?zhèn)魅霐?shù)據(jù)即可,代碼如下:

<template name="tabBar">  
  <view class="flex-h" style="color: {{tabBar.color}}; background: {{tabBar.backgroundColor}}; {{tabBar.position=='top'? 'top: 0' : 'bottom: 0'}}; {{tabBar.borderStyle? (tabBar.position=='top'? 'border-bottom: solid 1px '+tabBar.borderStyle + ';' : 'border-top: solid 1px '+tabBar.borderStyle + ';') : ''}}">  
  <block wx:for="{{tabBar.list}}" wx:key="pagePath">  
    <navigator url="{{item.pagePath}}" open-type="{{item.pageTum}}" class="menu-item" style="{{item.active? 'color: '+(item.selectedColor? item.selectedColor : tabBar.selectedColor) : ''}}">  
      <image src="{{item.selectedIconPath}}" wx:if="{{item.active}}"></image>  
      <image src="{{item.iconPath}}" wx:if="{{!item.active}}"></image>  
      <text>{{item.text}}</text>  
    </navigator>  
    </block>  
  </view>  
</template>

接下來是在index.js的配置對象:

tabBar:{
    "color": "#9E9E9E",
    "selectedColor": "#f00",
    "backgroundColor": "#fff",
    "borderStyle": "#ccc",
    "list":[{
            "pagePath": "/pages/index/index",
            "text": "主頁",
            "iconPath": "../../images/index.png",
            "selectedIconPath": "../../images/index_active.png",
            "pageTum": "redirect",
            "selectedColor": "#4EDF80",
            active: true
            },
            {
            "pagePath": "/pages/tum/tum",
            "text": "其他",
            "iconPath": "../../images/pageTum.png",
            "pageTum": "navigate",
            "selectedColor": "#4EDF80",
            active: false
            },
            {
            "pagePath": "/pages/mine/mine",
            "text": "我的",
            "iconPath": "../../images/mine.png",
            "selectedIconPath": "../../images/mine_active.png",
            "pageTum": "redirect",
            "selectedColor": "#4EDF80",
            active: false
            }],
            "position": "bottom"
    }
}

在這里要注意的是,active表示該頁面是否被選中,pageTum表示點擊該頁面跳轉方式,‘其他’這個頁面不用設置tabBar,并且它的pageTum的值是navigate,表示點擊‘其他’跳轉的頁面就不會顯示tabBar。

index.wxml引入模板:

<import src="../template/tabBar.wxml" />  
<template is="tabBar" data="{{tabBar: tabBar}}" /> 
<text>主頁面</text>    //顯示內容

然后在mine頁面也一樣配置數(shù)據(jù)把active的值改為true,引入模板。效果如下:

方法二:使用中間頁面跳轉

使用原生tabBar跳轉至一級頁面,再利用周期函數(shù)onShow的特性直接跳轉到我們需要看到的頁面,并且在返回時使用wx.swicthTab跳轉至程序設計所需的一級頁面。下面來看一看實現(xiàn)方法:

首先在app.json中設置tabBar

"tabBar": {
        "color": "#9E9E9E",
        "selectedColor": "#f00",
        "backgroundColor": "#fff",
        "borderStyle": "#ccc",
        "list": [{
                "pagePath": "pages/index/index",
                "text": "主頁",
                "iconPath": "images/index.png",
                "selectedIconPath": "images/index_active.png"
            },
            {
                "pagePath": "pages/tum/pageTum",
                "text": "其他",
                "iconPath": "images/pageTum.png"
            },
            {
                "pagePath": "pages/mine/mine",
                "text": "我的",
                "iconPath": "images/mine.png",
                "selectedIconPath": "images/mine_active.png"
            }
        ]
    }

在‘其他’這個頁面中設置跳轉頁面為一個中間過渡頁面pageTum,然后利用pageTum的周期函數(shù)onShow跳轉至無tabBar的二級頁面tum,返回時就能直接返回至主頁面,代碼如下:

data: {
        num: 0,
    },
    onLoad: function() {},
    onShow: function() {
        this.data.num++;
        if (this.data.num % 2 == 0) {
            wx.switchTab({
                url: '../index/index'
            });
        } else {
            wx.navigateTo({
                url: './tum'
            })
        }
    }

實現(xiàn)效果

如果有錯誤或者其他的方法,希望可以指出和交流,謝謝!

相關案例查看更多