PS后续:

  说来惭愧, 没想到这篇文章浏览的人有点多. 说实话写的挺乱的. 并且自定义tabbar还有闪屏的问题.

  因为有好几位道友都问了这个问题,  其中一位因为项目很急,所以就研究了一下(也是借鉴大佬的想法),  差不多解决了闪屏的问题.但还是有点小瑕疵.

  解决自定义tabbar闪屏的问题, 参考链接: https://developers.weixin.qq.com/community/develop/doc/000c6e038c0ce05413f71e7ce56c04

  本人也是前端路上的小白(工作满打满算才 一年半...), 所以写的有什么不对的地方, 还望指出呐.

  解决闪屏的代码就直接放压缩包链接了, 需要的话可以下载去借鉴 : https://files.cnblogs.com/files/yk95/wepy-poster-test.zip 

    运行项目之前, 还是去看一下大佬的文章, 这样思路更清晰.

    运行项目, 需要对wepy有所了解, 不了解的可以去查看官方文档, 

    还有小程序项目的appId需要弄成测试号, 不然这是我的(因为懒,就没删appId),没法跑.

    还有, 项目的初始页面得是自定义tabbar页面的其中一个, 也就是在app.json中config下的pages,  不然的话会出问题(否则只能在每个页面去隐藏官方tabbar了)  -- 先看参考链接, 先看参考链接, 先看参考链接,

对于下面的文章, 因为写的不好, 并且问题也多, 所以不建议去看了. 可以直接下载代码压缩包,毕竟在编译器上看代码还是最爽的.

因为需求,小程序自带的tabBar不能满足, 所以只能来自己重新写一个. 先看效果图吧

 首页:

发现:

消息:

我的:

接下来看代码:

1- 组件-- tabBarBottom.wpy  这里页面也可以用循环来写, 不过就要在样式上再去调整, 我这里没有用循环, 就将就看吧..... 

  view 中的 c-y 与 c-gray 是公共样式中, 控制图标颜色的切换;  因为这里的图标我用的是阿里云图标, 不是图片, 可以自己替换成图片, 根据 selected 进行图片切换

<template>
<view class="tabBarBox">
<!-- 首页 -->
<navigator class="itemView" url="{{tabBar.list[0].pagePath}}" open-type="redirect" hover-class="none">
<view class="item_icon {{tabBar.list[0].selected ? 'c-y' : 'c-gray'}} {{tabBar.list[0].icon_class}}"></view>
        //如果替换成图片 写法 替换图片注意样式, 样式应该要进行调整
        //<image class="" src="{{tabBar.list[0].selected ? 'tabBar.list[0].img_act' : 'tabBar.list[0].img'}}">
<view class="item_text {{tabBar.list[0].selected ? 'c-y' : 'c-gray'}}">{{tabBar.list[0].text}}</view>
</navigator>
<!-- 发现 -->
<navigator class="itemView" url="{{tabBar.list[1].pagePath}}" open-type="redirect" hover-class="none">
<view class="item_icon {{tabBar.list[1].selected ? 'c-y' : 'c-gray'}} {{tabBar.list[1].icon_class}}"></view>
<view class="item_text {{tabBar.list[1].selected ? 'c-y' : 'c-gray'}}">{{tabBar.list[1].text}}</view>
</navigator>
<!-- 发布 -->
<view class="addView">
<image class="add_icon" src="../images/add.png"></image>
</view>
<!-- 消息 -->
<navigator class="itemView2 itemView" url="{{tabBar.list[2].pagePath}}" open-type="redirect" hover-class="none">
<view class="item_icon {{tabBar.list[2].selected ? 'c-y' : 'c-gray'}} {{tabBar.list[2].icon_class}}"></view>
<view class="item_text {{tabBar.list[2].selected ? 'c-y' : 'c-gray'}}">{{tabBar.list[2].text}}</view>
</navigator>
<!-- 我的 -->
<navigator class="itemView" url="{{tabBar.list[3].pagePath}}" open-type="redirect" hover-class="none">
<view class="item_icon {{tabBar.list[3].selected ? 'c-y' : 'c-gray'}} {{tabBar.list[3].icon_class}}"></view>
<view class="item_text {{tabBar.list[3].selected ? 'c-y' : 'c-gray'}}">{{tabBar.list[3].text}}</view>
</navigator>
<!-- <view></view> -->
</view>
</template>
<script>
import wepy from 'wepy';
export default class tabBar extends wepy.component {
// props 接收父组件传递过来的值
props = {  
    // 接收父级传递的tabBar信息
tabBar: {
type: Object,
default: {}
}
} components = { } data = { } onLoad() { } computed = {}
methods = { }
event = {}
}
</script>
<style lang="scss">
.tabBarBox{
width: 100%;
height: 100rpx;
background-color: #fff;
position: fixed;
bottom: 0;
z-index: 9999;
border-top: 1px #afafaf solid;
}
.itemView2{
margin-left: 150rpx;
}
.itemView{
width: 150rpx;
height: 100rpx;
text-align: center;
display: inline-block;
padding-top: 6rpx;
.item_icon{
font-size: 50rpx;
}
.item_text{
font-size: 28rpx;
}
}
.addView{
width: 150rpx;
position: fixed;
bottom: 0;
text-align: center;
display: inline-block;
.add_icon{
width: 120rpx;
height: 120rpx;
}
}
</style>

2- tabBar的数据 , 我放在了启动文件中 app.wpy

   globalData = {
userInfo: null,
    // tabBar数据
tabBar:{
list: [
{
pagePath: "home",
text: "首页",
icon_class: "iconfont icon-tab-home", //这里用的是阿里图标, 可以替换成图片
selected: true
        //图片写法
        // img: '未选中的图片路径',
        // img_act: '被选中的图片路径'
},
{
pagePath: "find",
text: "发现",
icon_class: "iconfont icon-tab-find",
selected: false
},
{
pagePath: "news",
text: "消息",
icon_class: "iconfont icon-tab-news",
selected: false
},
{
pagePath: "myInfo",
text: "我的",
icon_class: "iconfont icon-tab-my",
selected: false
}
]
}
}
    // 处理tabBar中点击, 被点击,将当前的数据对象中 selected 改成true, 其余的就得改成 false; 这里的id是标识, 在调用时手动传入的; id 与 tabBar数组每一个对象索引要对应
tabBarClickHandle(id, that) {
let tbList = this.globalData.tabBar.list;
tbList.forEach((item, index) => {
if (id == index) {
tbList[id].selected = true;
} else {
tbList[index].selected = false;
}
});
that.$apply();
return this.globalData.tabBar;
}

3- 首页中使用组件  剩余的 发现,消息,我的这三个页面中都是这样的用法, 都是这五步, 不过剩余的三个 在第四步中 id要变   发现--id-1  消息--id-2  我的--id-3

 <template>
<view id="HomePage">
<view>
          // ⑤: 使用组件, 将数据传递给组件
<tabBarBottom :tabBar.sync="tabBarData"></tabBarBottom>
</view>
</view>
</template>
<script>
import wepy from 'wepy';
import tabBarBottom from '@/components/tabBarBottom'; //①:先导入组价
export default class Home extends wepy.page{
config = {
navigationBarTitleText: "首页
}
components = {
tabBarBottom, // ② 声明组件
}
data = {
tabBarData: {}, //③ 组件数据 <传递给组件的>
}
onLoad() {
        //④: 获取数据,更新数据 tabBarClickHandle()启动文件中编写的---- 0就是形参id的实参
         this.tabBarData = this.$parent.tabBarClickHandle(0, this);
this.$apply();
}
computed = { }
methods = { }
event = { }
}
</script>

慢慢积累,慢慢成长,加油!!

文章中如果有错误,请您指出,我会第一时间去修改;

①:

Wepy--小程序自定义底部tabBar的更多相关文章

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

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

  2. 小程序自定义底部tab

    首页wxml的代码: <view class="nav" hover-class="none"> <view class="inde ...

  3. 微信小程序自定义底部导航栏组件+跳转

    微信小程序本来封装有底部导航栏,但对于想自定义样式和方法的开发者来说,这并不是很好. 参考链接:https://github.com/ljybill/miniprogram-utils/tree/ma ...

  4. 小程序之底部tabBar

    用法简介: 1.app.json中配置下tabBar即可,注意tabBar至少需要两个最多五个Item选项 这里简单列举一些属性值:对于tabBar整体属性设置: 对于tabBar中每个Item属性设 ...

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

    微信小程序自定义tabbar的实现 目的:当采用微信的自定义tabbar组件的时候,切换的时候会出现闪屏的效果:当使用微信默认的tabbar的时候,限制了tabbar的数量以及灵活配置. 方案:自己动 ...

  6. 微信小程序自定义 tabbar

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

  7. 微信小程序把玩(三)tabBar底部导航

    原文:微信小程序把玩(三)tabBar底部导航 tabBar相对而言用的还是比较多的,但是用起来并没有难,在app.json中配置下tabBar即可,注意tabBar至少需要两个最多五个Item选项 ...

  8. 微信小程序自定义TabBar

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

  9. 快速入门 WePY 小程序【转】

    一.WePY介绍 WePY 是 腾讯 参考了Vue 等框架对原生小程序进行再次封装的框架,更贴近于 MVVM 架构模式, 并支持ES6/7的一些新特性. 二.WePY 使用 1.WePY的安装或更新都 ...

随机推荐

  1. VS2008集成QT的OpenGL开发(实现二维图形的旋转)

    主要是利用Qt中的定时器实现了二维图形的旋转功能: #ifndef QGLTEST_H #define QGLTEST_H #include <QGLWidget> #include &l ...

  2. flex笔记 - 基础

    flex笔记 - 基础 文章中的所有图示代码都放在了github上: 阮一峰flex博客跟学代码 传统的布局解决方案,基于盒模型, 依赖 display, position, float属性来进行布局 ...

  3. JavaScript JSON简单操作(增删改)

    JavaScript 中对json处理: 声明;: var json={};或 json={"name":"asd","age":24}; ...

  4. vue项目使用简略总结

    1.利用iView Cli搭建项目结构2.搭建完毕之后将proxy.js和'Server.js'放置到node_modules\webpack-dev-server\lib目录下,以实现跨域访问公司平 ...

  5. Python面向对象----多态和鸭子类型

    1. C#中多态实现的条件是 继承, 重写以及父类指向子类. 但是在弱类型Python里面, 实现多态的条件就显得很简洁, 只需要在子类中实现父类相同名称的方法即可. 2. 鸭子类型的解释: 若一个类 ...

  6. uni-app 路由navigate

    uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS.Android.H5.小程序等多个平台. 公司最近在写APP应用到了uni-app  我在写的时 ...

  7. hdu 2435dinic算法模板+最小割性质

    hdu2435最大流最小割 2014-03-22 我来说两句 来源:hdu2435最大流最小割 收藏 我要投稿 2435 There is a war 题意: 给你一个有向图,其中可以有一条边是无敌的 ...

  8. 单词数 (STL set集合)

    单词数 Problem Description lily的好朋友xiaoou333近期非常空.他想了一件没有什么意义的事情.就是统计一篇文章里不同单词的总数.以下你的任务是帮助xiaoou333解决问 ...

  9. 调用imagemagick做响应图片

    设计出图后经常需要改下尺寸放在别的项目上使用,每次都是设计手工处理,其实图片服务可以做更多事情,比如借助强大的im,可以通过url控制图片尺寸 var childProcess = require(' ...

  10. .NET开源的背后:是无奈,还是顺应潮流?

    摘要:微软.NET的开源,让很多开发者欣喜若狂.同一时候也有很多人好奇其背后的故事,过去视开源为癌症的微软为什么会突然有这一举措,是出于无奈,还是顺应潮流,而这当中的种种也许能够用文中的六个观点来说明 ...