Coder Social home page Coder Social logo

weapp-component-tabbar's Introduction

weapp-component-tabbar

微信小程序自定义组件:带未读数目的tab按钮

组件的使用

可以直接复制dist中的文件,到你的项目的pages页。如果放到其他的目录,需要相应修改下列引用中的路径( ./path/to/file/tabbar.subfix )

index.wxml (页面的 wxml文件中)

<!-- 在需要的页面的头部 引入wxml -->
<import src="../template/tabbar.wxml"/>
<!-- 直接引入 -->
<template is="tab-bar" data="{{ jhDataForTabbar }}"/>

<!--
    其他的页面的元素
 -->

index.wxss (页面的 wxss 文件)

 /* 引入tabbar的样式 */
 @import "../template/tabbar.wxss";

index.js (页面的 js 文件)

文件头部:
import {
   init,                    // 初始化组件及页面
   Tabbar,                  // Tabbar是组件的事件注册中心
   setTabbarData            // 设置/更新 tabbar显示的数据
} from "../template/tabbar";
文件内部:调用init(object)函数,初始化页面
let UserPageData = {
    data: {
        name: "Jonham.Chen"
    },
    onLoad: function() {
    },
    // ... any others
};

init(UserPageData);
文件内部:调用setTabbarData(object)函数,设置及更新tabbar的数据
const tabbarData = [];
tabbarData.push({
    iCount: 1,              //未读数目
    sIconUrl: 'imageUrl',   //按钮图标的url或者 相对路径
    sTitle: "title",        //按钮名称
});

setTabbarData(tabbarData);
文件内部:调用Tabbar.addListener(fn)函数增加tab的监听事件
/** Tabbar.addListener( fn )     增加监听事件
  *       .removeListener( fn )  移除监听事件
  *       .removeAll()           移除所有监听事件
  *
*/
Tabbar.addListener(function(ev) {
    console.log(ev);
    // ev.key === 'note'
    // ev的key对应被点击的tab的title
});

PS: 当然,可以通过 git clone https://github.com/Jonham/weapp-component-tabbar.git 命令,直接用 微信开发者工具 打开目录即可预览。

使用中,有任何问题、建议,请在issue页提交。或者联系我[ [email protected] ]

weapp-component-tabbar's People

Contributors

jonham avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.