微信小程序自定义tabbar的实现

目的:当采用微信的自定义tabbar组件的时候,切换的时候会出现闪屏的效果;当使用微信默认的tabbar的时候,限制了tabbar的数量以及灵活配置。

方案:自己动手写一个和微信小程序提供的tabbar相同的效果,而且还可以满足灵活配置的功能.有参照有赞小程序

效果:

  1. 效果A:

2.效果B:

实现:

             项目结构如下:

       

            II 效果A实现:

1》wxml的代码:

Page({
data: {
blockid:0,
bgcolor:'#ffffff',
color:"#cccccc",
selectedColor:'#333333',
showborder:false,
bordercolor:"",
tabbar:[
{
pagePath: "page/home0/index",
selectedIconPath: '/resources/tabbar/homeh.png',
iconPath: '/resources/tabbar/home.png',
text: '首页A',
isdot: false,
number: 0
}, {
pagePath: "page/home1/index",
selectedIconPath: '/resources/tabbar/kindh.png',
iconPath: '/resources/tabbar/kind.png',
text: '首页B',
isdot: true,
number: 0
}, {
pagePath: "page/home2/index",
selectedIconPath: '/resources/tabbar/myh.png',
iconPath: '/resources/tabbar/my.png',
text: '首页C',
isdot: false,
number: 5
}, {
pagePath: "page/home3/index",
selectedIconPath: '/resources/tabbar/shopcarth.png',
iconPath: '/resources/tabbar/shopcart.png',
text: '首页D',
isdot: false,
number: 0
}
]
},
// event.detail 的值为当前选中项的索引
tabbarChange(e) { var index = parseInt(e.detail);
this.setData({
blockid:index
})
}
})

2》json文件如下:

{
"usingComponents": {
"tabbar": "../../components/tabbar/index"
}
}
          3》js文件如下:

Page({
data: {
blockid:0,
bgcolor:'#ffffff',
color:"#cccccc",
selectedColor:'#333333',
showborder:false,
bordercolor:"",
tabbar:[
{
pagePath: "page/home0/index",
selectedIconPath: '/resources/tabbar/homeh.png',
iconPath: '/resources/tabbar/home.png',
text: '首页A',
isdot: false,
number: 0
}, {
pagePath: "page/home1/index",
selectedIconPath: '/resources/tabbar/kindh.png',
iconPath: '/resources/tabbar/kind.png',
text: '首页B',
isdot: true,
number: 0
}, {
pagePath: "page/home2/index",
selectedIconPath: '/resources/tabbar/myh.png',
iconPath: '/resources/tabbar/my.png',
text: '首页C',
isdot: false,
number: 5
}, {
pagePath: "page/home3/index",
selectedIconPath: '/resources/tabbar/shopcarth.png',
iconPath: '/resources/tabbar/shopcart.png',
text: '首页D',
isdot: false,
number: 0
}
]
},
// event.detail 的值为当前选中项的索引
tabbarChange(e) { var index = parseInt(e.detail);
this.setData({
blockid:index
})
}
})

        III效果B实现:

1》wxml的代码:

<block wx:if="{{blockid==0}}">
这里是首页A
</block>
<block wx:if="{{blockid==1}}">
这里是首页B
</block>
<block wx:if="{{blockid==2}}">
这里是首页C
</block>
<block wx:if="{{blockid==3}}">
这里是首页D
</block> <!--底部tabbar【一般正常用法,index页面特殊用法】-->
<tabbar tabbarData="{{tabbar}}" active="{{0}}" bgcolor="{{bgcolor}}" color="{{color}}" selectedColor="{{selectedColor}}" showborder="{{showborder}}" bind:tapChange="tabbarChange" />

2》json的代码

{
"usingComponents": {
"tabbar": "../../components/tabbar/index"
}
}

3》js的代码

Page({

  /**
* 页面的初始数据
*/
data: {
blockid: 0,
bgcolor: 'green',
color: "red",
selectedColor: 'blue',
showborder: false,
bordercolor: "",
tabbar: [{
pagePath: "page/home0/index",
selectedIconPath: '/resources/tabbar/homeh.png',
iconPath: '/resources/tabbar/home.png',
text: '首页A',
}, {
pagePath: "page/home1/index",
selectedIconPath: '/resources/tabbar/kindh.png',
iconPath: '/resources/tabbar/kind.png',
text: '首页B',
}, {
pagePath: "page/home2/index",
selectedIconPath: '/resources/tabbar/myh.png',
iconPath: '/resources/tabbar/my.png',
text: '首页C',
}, {
pagePath: "page/home3/index",
selectedIconPath: '/resources/tabbar/shopcarth.png',
iconPath: '/resources/tabbar/shopcart.png',
text: '首页D',
}]
},
// event.detail 的值为当前选中项的索引
tabbarChange(e) { var index = parseInt(e.detail);
this.setData({
blockid: index
})
},
})

github地址如下:https://github.com/weiyunhelong/WeChatTabbar,欢迎下载并使用!

微信小程序自定义tabbar的实现的更多相关文章

  1. 微信小程序自定义 tabbar

    一定的需求情况下,无法使用小程序原生的 tabbar 的时候,需要自行实现一个和 tabbar 功能一模一样的自制组件. 查阅了海量的博客和文档之后,亲自踩坑.总结了三种在不使用微信小程序原生 tab ...

  2. 微信小程序自定义tabbar的问题

    个人感觉小程序的tab样式自定义的能力有所欠缺,不够美观,于是今天自己diy了一个tab 测试的时候发现,无论是使用navigator跳转(会出现点击的效果)还是用bindtap(触摸),因为没有定义 ...

  3. 微信小程序 自定义tabbar实例

    在小程序的开发文档中,对tabbar是这样说明的: 如果小程序是一个多 tab 应用(客户端窗口的底部或顶部有 tab 栏可以切换页面),可以通过 tabBar 配置项指定 tab 栏的表现,以及 t ...

  4. 微信小程序自定义TabBar

    项目中需要根据用户角色控制TabBar中各Item的显示和隐藏,然而小程序自带TabBar没有提供隐藏某个item的功能,只好自己动手写了一个. 1.wxml文件 <view class=&qu ...

  5. 微信小程序 - 自定义tabbar

    更新: 2019-1-18:自定义tabbar组件已发布 各种奇葩的需求,造就了我们 wxml <view class="nav-tabs"> <view cla ...

  6. 微信小程序 - 自定义tabbar(组件)

    配置项(关于使用组件) index.wxml <!-- tabBar:tabBar配置 activeIndex: 激活页面下标 slots: 多插槽配置(需与页面一致) --> <t ...

  7. 微信小程序——自定义导航栏

    微信头部导航栏可能通过json配置: 但是有时候我们项目需求可能需要自定义头部导航栏,如下图所示: 现在具体说一下实现步骤及方法: 步骤: 1.在 app.json 里面把 "navigat ...

  8. 微信小程序自定义弹窗wcPop插件|仿微信弹窗样式

    微信小程序自定义组件弹窗wcPop|小程序消息提示框|toast自定义模板弹窗 平时在开发小程序的时候,弹窗应用场景还是蛮广泛的,但是微信官方提供的弹窗比较有局限性,不能自定义修改.这个时候首先想到的 ...

  9. 微信小程序-自定义底部导航

    代码地址如下:http://www.demodashi.com/demo/14258.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

随机推荐

  1. [20190929]bash使用bc计算的相关问题.txt

    [20190929]bash使用bc计算的相关问题.txt --//快放假没什么事情,使用bash写一些小程序,转化number到oracle number编码,使用bc计算功能,发现一些小问题--/ ...

  2. 如何在Appium中使用AI定位

    当我们在写自动化测试脚本的时候,传统情况下一定要知道元素的属性,如id.name.class等.那么通过AI的方式定位元素可能就不需要知道元素的属性,评价人对元素的判断来定位,比如,看到一个搜索框,直 ...

  3. Python—时间模块(time)和随机模块(random)

    时间模块 time模块 获取秒级时间戳.毫秒级时间戳.微秒级时间戳 import time t = time.time() print t # 原始时间数据 1574502460.90 print i ...

  4. 分布式系统ID的几种生成办法

    前言 一般单机或者单数据库的项目可能规模比较小,适应的场景也比较有限,平台的访问量和业务量都较小,业务ID的生成方式比较原始但是够用,它并没有给这样的系统带来问题和瓶颈,所以这种情况下我们并没有对此给 ...

  5. Ambassador中,启用不同的Load balancing算法

    默认就是轮循,如果要其它hash或是最少请求,那就需要作更多的设置了. https://www.getambassador.io/reference/core/load-balancer/#sourc ...

  6. vue全局路由守卫beforeEach+token验证+node

    在后端安装jsonwebtoken         npm i jsonwebtoken --save 在 login.js文件中引入      // 引入jwtconst jwt = require ...

  7. Pycharm软件更换pip默认安装源为国内安装源

    1.为什么这么做? Python里的pip是官方自带的源,国内使用pip安装的时候十分缓慢,所以最好是更换成中国国内的源地址. 2.准备工作: 目前国内靠谱的 pip 镜像源有: 清华: https: ...

  8. [C2W3] Improving Deep Neural Networks : Hyperparameter tuning, Batch Normalization and Programming Frameworks

    第三周:Hyperparameter tuning, Batch Normalization and Programming Frameworks 调试处理(Tuning process) 目前为止, ...

  9. template指针小测试

    测试结论: 1 函数指针 -- 使用形参固定的一系列函数作为某个函数的形参 -- callback机制 2 模板指针 -- 使用形参可变的一系列函数作为某个函数的形参 -- 3 typename -- ...

  10. 史上最全的LaTeX特殊符号语法

    史上最全的LaTeX特殊符号语法 运算符 语法 效果 语法 效果 语法 效果 + \(+\) - \(-\) \triangleleft \(\triangleleft\) \pm \(\pm\) \ ...