当前位置:   article > 正文

微信小程序(二)----------微信小程序自定义底部导航栏tabBar_微信小程序自定义底部tabbar

微信小程序自定义底部tabbar

1、说明

微信提供的tabBar很好用,但是也有很多限制,不能直接监控点击事件,也不能做酷炫的底部导航栏,想要实现个性化的底部导航栏那就自己写一个吧。

2、自定义导航栏实现步骤

2.1、模板的制作

小程序提供的公共模板的使用,将模板写在<template name=""></template>标签里面,这个页面也要加在app.json的pages里面,值得一提的是,小程序中表达式在判断赋值和样式加载上的运用确实很方便。

template.wxml:

  1. <template name="footer">
  2. <view class="tabBar">
  3. <block wx:for="{
  4. {tabBarList}}" wx:key="{
  5. {itemx}}" wx:for-index="itemx" data-itemx="{
  6. {itemx}}">
  7. <view class="tabBar-item" bindtap="swichTabBar">
  8. <image src="{
  9. {currentTabBar==itemx ? item.selectedIconPath:item.iconPath}}" mode="widthFix" class="tabBar-img"></image>
  10. <text class="tabBar-text {
  11. {currentTabBar==itemx ? 'active' : ''}}">{
  12. {item.text}}</text>
  13. </view>
  14. </block>
  15. </view>
  16. </template>

因为公共模板,所以参数最好在公共js里面管理,这里我用的全局变量管理模板参数。

app.js

  1. App({
  2. globalData: {//全局变量
  3. currentTabBar:0,
  4. tabBar:{
  5. list: [
  6. {
  7. text: 
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/869059
推荐阅读
相关标签
  

闽ICP备14008679号