微信小程序 WeUI·導(dǎo)航組件

2022-05-12 17:43 更新

Navigation

Navigation是小程序的頂部導(dǎo)航組件,當(dāng)頁面配置navigationStyle設(shè)置為custom的時候可以使用此組件替代原生導(dǎo)航欄。

示例代碼:

{
    "usingComponents": {
        "mp-navigation-bar": "../components/navigation-bar/navigation-bar"
    },
    "navigationStyle": "custom",
    "navigationBarTitleText": "UI組件庫"
}

<mp-navigation-bar loading="{{loading}}" show="{{show}}" animated="{{animated}}" color="{{color}}" background="{{background}}" title="UI組件庫" back="{{true}}"></mp-navigation-bar>
<view class="page">
    <view class="page__hd">
        <view class="page__title">Navigation</view>
        <view class="page__desc">小程序自定義導(dǎo)航欄</view>
    </view>
    <view class="page__bd page__bd_spacing">
        <button class="weui-btn" type="primary" bindtap="toggleLoading">觸發(fā)loading</button>
        <button class="weui-btn" type="primary" bindtap="changeColor">修改文字顏色</button>
        <button class="weui-btn" type="primary" bindtap="changeBgColor">修改背景顏色</button>
        <button class="weui-btn" type="primary" bindtap="toggleShow">顯示 / 隱藏</button>
        <button class="weui-btn" type="primary" bindtap="toggleAnimated">設(shè)置顯示 / 隱藏opacity動畫</button>
    </view>
</view>

Page({
  data: {
    loading: false,
    color: '#000',
    background: '#f8f8f8',
    show: true,
    animated: false
  },
  toggleLoading() {
    this.setData({
      loading: !this.data.loading
    })
  },
  changeColor() {
    this.setData({
      color: '#07C160'
    })
  },
  changeBgColor() {
    this.setData({
      background: '#ededed'
    })
  },
  toggleShow() {
    this.setData({
      show: !this.data.show
    })
  },
  toggleAnimated() {
    this.setData({
      animated: !this.data.animated,
      show: !this.data.show
    })
  }
})


屬性列表

屬性 類型 默認(rèn)值 必填 說明
ext-class string 添加在組件內(nèi)部結(jié)構(gòu)的class,可用于修改組件內(nèi)部的樣式
title string 導(dǎo)航標(biāo)題,如果不提供,則名為center的slot有效
back boolean true 是否顯示返回按鈕,默認(rèn)點(diǎn)擊按鈕會執(zhí)行navigateBack,如果為false,則名為left的slot有效
delta number 1 當(dāng)back為true的時候有效,表示navigateBack的delta參數(shù)
background string #f8f8f8 導(dǎo)航背景色
color string 導(dǎo)航顏色
loading boolean 是否顯示標(biāo)題左側(cè)的loading
show boolean 顯示隱藏導(dǎo)航,隱藏的時候navigation的高度占位還在
animated boolean 顯示隱藏導(dǎo)航的時候是有opacity過渡動畫
bindback eventhandler 在back為true時,點(diǎn)擊back按鈕觸發(fā)此事件,detail包含delta

Slot

名稱 描述
left 左側(cè)slot,在back按鈕位置顯示,當(dāng)back為false的時候有效
center 標(biāo)題slot,在標(biāo)題位置顯示,當(dāng)title為空的時候有效
right 在導(dǎo)航的右側(cè)顯示

Tabbar

Tabbar組件,也可以用來作為小程序的自定義Tabbar使用

示例代碼:

{
  "usingComponents": {
    "mp-tabbar": "../components/tabbar/tabbar"
  },
  "navigationBarTitleText": "UI組件庫"
}

<view class="page">
    <view class="page__hd">
        <view class="page__title">Tabbar</view>
        <view class="page__desc">類似小程序原生tabbar的組件,可用于自定義tabbar</view>
    </view>
    <mp-tabbar style="position:fixed;bottom:0;width:100%;left:0;right:0;" list="{{list}}" bindchange="tabChange"></mp-tabbar>
</view>

Page({
    data: {
        list: [{
            "text": "對話",
            "iconPath": "../../images/tabbar_icon_chat_default.png",
          "selectedIconPath": "../../images/tabbar_icon_chat_active.png",
            dot: true
        },
        {
            "text": "設(shè)置",
          "iconPath": "../../images/tabbar_icon_setting_default.png",
          "selectedIconPath": "../../images/tabbar_icon_setting_active.png",
            badge: 'New'
        }]
    },
    tabChange(e) {
        console.log('tab change', e)
    }
});


屬性列表

屬性類型默認(rèn)值必填說明
ext-classstring添加在組件內(nèi)部結(jié)構(gòu)的class,可用于修改組件內(nèi)部的樣式
listarray<object>Tabbar的項的數(shù)組,按照規(guī)范,至少要有2個Tabbar項
currentnumber0當(dāng)前選中的Tabbar項的下標(biāo)
bindchangeeventhandlerTabbar項發(fā)生改成的時候觸發(fā)此事件,detail為{index, item},index是Tabbar下標(biāo),item是對應(yīng)的Tabbar項的配置

list屬性是對象數(shù)組,每一項表示一個Tabbar項,其字段含義為

字段名類型默認(rèn)值必填說明
textstringTabbar項的標(biāo)題
iconPathstringTabbar項的icon圖片路徑,建議使用絕對路徑,相對路徑要相對于組件所在目錄的。
selectedIconPathstringTabbar項選中時的icon,建議使用絕對路徑,相對路徑要相對于組件所在目錄的。
badgestring是否顯示Tabbar的右上角的Badge


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號