微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解

本文实例讲述了微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能。分享给大家供大家参考,具体如下:

为岳麓等地区用户提供了全套网页设计制作服务,及岳麓网站建设行业解决方案。主营业务为网站制作、成都网站设计、岳麓网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

微信小程序开发中选项卡.在android中选项卡一般用fragment,到了小程序这里瞬间懵逼了.

总算做出来了.分享出来看看.

先看效果:

微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解

再上代码:

1.index.wxml



  哈哈
  呵呵
  嘿嘿


  
  
   我是哈哈
  
  
  
   我是呵呵
  
  
  
   我是嘿嘿
  


2.index.wxss

/**index.wxss**/
.swiper-tab{
  width: 100%;
  border-bottom: 2rpx solid #777777;
  text-align: center;
  line-height: 80rpx;}
.swiper-tab-list{ font-size: 30rpx;
  display: inline-block;
  width: 33.33%;
  color: #777777;
}
.on{ color: #da7c0c;
  border-bottom: 5rpx solid #da7c0c;}
.swiper-box{ display: block; height: 100%; width: 100%; overflow: hidden; }
.swiper-box view{
  text-align: center;
}

3.index.js

//index.js
//获取应用实例
var app = getApp()
Page( {
 data: {
  /**
    * 页面配置
    */
  winWidth: 0,
  winHeight: 0,
  // tab切换
  currentTab: 0,
 },
 onLoad: function() {
  var that = this;
  /**
   * 获取系统信息
   */
  wx.getSystemInfo( {
   success: function( res ) {
    that.setData( {
     winWidth: res.windowWidth,
     winHeight: res.windowHeight
    });
   }
  });
 },
 /**
   * 滑动切换tab
   */
 bindChange: function( e ) {
  var that = this;
  that.setData( { currentTab: e.detail.current });
 },
 /**
  * 点击tab切换
  */
 swichNav: function( e ) {
  var that = this;
  if( this.data.currentTab === e.target.dataset.current ) {
   return false;
  } else {
   that.setData( {
    currentTab: e.target.dataset.current
   })
  }
 }
})

之前没有上传代码.这是下图的代码

demo源码点击此处本站下载

微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解

这样一个类似viewpage的顶部选项卡就出来了.

微信小程序开发中窗口底部tab栏切换页面很简单很方便.

微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解

代码:

1.app.json

//app.json
{
 "pages":[
  "pages/index/index",
  "pages/logs/logs"
 ],
 "window":{
  "backgroundTextStyle":"light",
  "navigationBarBackgroundColor": "#999999",
  "navigationBarTitleText": "tab",
  "navigationBarTextStyle":"white"
 },
  "tabBar": {
  "color": "#ccc",
  "selectedColor": "#35495e",
  "borderStyle": "white",
  "backgroundColor": "#f9f9f9",
  "list": [
   {
    "text": "首页",
    "pagePath": "pages/index/index",
    "iconPath": "images/home.png",
    "selectedIconPath": "images/home-actived.png"
   },
   {
    "text": "目录",
    "pagePath": "pages/catalogue/catalogue",
    "iconPath": "images/note.png",
    "selectedIconPath": "images/note-actived.png"
   },
   {
    "text": "我的",
    "pagePath": "pages/mine/mine",
    "iconPath": "images/profile.png",
    "selectedIconPath": "images/profile-actived.png"
   }
  ]
 }
}

pagePath是页面路径.iconPath是图片路径,icon 大小限制为40kb.
selectedIconPath:选中时的图片路径,icon 大小限制为40kb

tab Bar的最多5个,最少2个.

在pages目录下写好页面即可切换.

希望本文所述对大家微信小程序开发有所帮助。


文章标题:微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解
新闻来源:http://bzwzjz.com/article/gsojip.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 营销型网站建设 定制网站建设 网站设计 网站设计 成都网站建设 盐亭网站设计 自适应网站建设 成都网站建设公司 网站设计公司 成都h5网站建设 营销型网站建设 成都网站设计公司 成都网站设计公司 网站建设公司 古蔺网站建设 企业网站建设公司 成都网站设计制作公司 做网站设计 成都网站设计 网站制作公司 H5网站制作 响应式网站设计