一、功能描述

在同一个页面内实现不同展示页面的切换功能,如下图所示

二、代码实现

1. index.js

  1. Page({
  2.  
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. currentData : 0,
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. },
  14. //获取当前滑块的index
  15. bindchange:function(e){
  16. const that = this;
  17. that.setData({
  18. currentData: e.detail.current
  19. })
  20. },
  21. //点击切换,滑块index赋值
  22. checkCurrent:function(e){
  23. const that = this;
  24.  
  25. if (that.data.currentData === e.target.dataset.current){
  26. return false;
  27. }else{
  28.  
  29. that.setData({
  30. currentData: e.target.dataset.current
  31. })
  32. }
  33. }
  34. })

  

  

2. index.wxml

  1. <view class='topTabSwiper'>
  2. <view class='tab {{currentData == 0 ? "tabBorer" : ""}}' data-current = "0" bindtap='checkCurrent'>推荐</view>
  3. <view class='tab {{currentData == 1 ? "tabBorer" : ""}}' data-current = "1" bindtap='checkCurrent'>热点</view>
  4. <view class='tab {{currentData == 2 ? "tabBorer" : ""}}' data-current = "2" bindtap='checkCurrent'>关注</view>
  5. </view>
  6. <swiper current="{{currentData}}" class='swiper' style="height:600px;" duration="300" bindchange="bindchange">
  7. <swiper-item><view class='swiper_con'>welcome come to 推荐</view></swiper-item>
  8. <swiper-item><view class='swiper_con'>welcome come to 热点</view></swiper-item>
  9. <swiper-item><view class='swiper_con'>welcome come to 关注</view></swiper-item>
  10. </swiper>

  

3. index.wxss

  1. .tab {
  2. float: left;
  3. width: 33.3333%;
  4. text-align: center;
  5. padding: 10rpx 0;
  6. }
  7.  
  8. .topTabSwiper {
  9. border-top: 1px solid #ccc;
  10. border-bottom: 1px solid #ccc;
  11. zoom: 1;
  12. }
  13.  
  14. .topTabSwiper:after {
  15. content: "";
  16. clear: both;
  17. display: block;
  18. }
  19.  
  20. .tabBorer {
  21. border-bottom: 1px solid #f00;
  22. color: #f00;
  23. }
  24.  
  25. .swiper {
  26. width: 100%;
  27. }
  28.  
  29. .swiper_con {
  30. text-align: center;
  31. width: 100%;
  32. height: 100%;
  33. padding: 80rpx 0;
  34. }

  

微信小程序:选项卡页面切换的更多相关文章

  1. 微信小程序左右滑动切换页面示例代码--转载

    微信小程序——左右滑动切换页面事件 微信小程序的左右滑动触屏事件,主要有三个事件:touchstart,touchmove,touchend. 这三个事件最重要的属性是pageX和pageY,表示X, ...

  2. 微信小程序前端页面书写

    微信小程序前端页面书写 WXML(WeiXin Markup Language)是框架设计的一套标签语言,结合基础组件.事件系统,可以构建出页面的结构. 一.数据绑定 1. 普通写法 <view ...

  3. 微信小程序写tab切换

    微信小程序之tab切换效果,如图: 最近在学习微信小程序并把之前的公司app搬到小程序上,挑一些实现效果记录一下(主要是官方文档里没说的,毕竟官方文档只是介绍功能) .wxml代码: <view ...

  4. 微信小程序:页面配置 page.json

    微信小程序:页面配置 page.json 一.页面配置 page.json 如果整个小程序的风格是蓝色调,那么可以在 app.json 里边声明顶部颜色是蓝色即可. 实际情况可能不是这样,可能你小程序 ...

  5. 微信小程序开发--页面结构

    一.微信小程序开发--页面文件组成 [page.name].js 页面逻辑文件,用于创建页面对象,以及处理页面生命周期控制和数据处理 [page.name].wxml wxml指的是Wei Xin M ...

  6. 图解微信小程序---实现页面的跳转与返回操作

    图解微信小程序---实现页面的跳转与返回操作 代码笔记 操作步骤 第一步:在app.json配置文件中,创建跳转页面 第二步:编写首页跳转(注意跳转方式,和设置点击样式类名) 第三步:编写首页样式 第 ...

  7. 微信小程序开发--路由切换,页面重定向

    这段时间开发了一个微信小程序,虽然小程序的导航API 官方文档写得很详细,但是在具体开发过程中还是会遇到很多不明白,或者一时转不过弯的地方. 1.页面切换传参,参数读取 1.1  wx.navigat ...

  8. 微信小程序之页面路由

    路由方式 简介 对于路由的触发方式以及页面生命周期函数如下: 路由方式 触发时机 路由前页面 路由后页面 初始化 小程序打开的第一个页面   onLoad, onSHow 打开新页面 调用 API w ...

  9. 微信小程序之 页面跳转 及 调用本地json的假数据调试

    一.微信小程序 跳转页面 小程序页面有2种跳转,可以在wxml页面或者js中: (1)在wxml页面中: <navigator url="../index/index"> ...

  10. 微信小程序WXML页面常用语法(讲解+示例)

    (一) WXML 是什么 官方说明:WXML(WeiXin Markup Language)是框架设计的一套标签语言,结合基础组件.事件系统,可以构建出页面的结构 在前面我们就已经提过,WXML,就可 ...

随机推荐

  1. Entity Framework之DB First方式

    EF(Entity Framework的简称,下同)有三种方式,分别是:DataBase First. Model First和Code First. 下面是Db First的方式: 1. 数据库库中 ...

  2. [C++] 用Xcode来写C++程序[7] Class

    用Xcode来写C++程序[7] Class 不带构造函数的Rectangle类 // // Rectangle.h // Plus // // Created by YouXianMing on 1 ...

  3. AD用户登录验证,遍历OU(LDAP)

    先安装python-ldap模块 1.验证AD用户登录是否成功 import sqlite3,ldap domainname='cmr\\' username='zhangsan' ldapuser ...

  4. Spring Boot+MyBabits静态连接多个数据库

    1.修改.properties first.datasource.jdbc-url=jdbc:mysql://localhost/forwind first.datasource.username=r ...

  5. jQuery Ajax url使用方式

    jQuery Ajax的使用场景: 页面需要通过后台逻辑,但只需要局部刷新以显示新的内容. jQuery Ajax url使用方式1.servlet方式: 需要在struts.xml中写一个actio ...

  6. September 05th 2017 Week 36th Tuesday

    I always in the deepest despair, meet the most beautiful sunrise. 我总是在最深的绝望里遇见最美丽的惊喜. Some pessimist ...

  7. Inter-System Differencing between GPS and BDS for Medium-Baseline RTK Positioning-12-18

    顾及系统间偏差的双系统中长基线RTK定位 主要适用于:严峻地区,比如城市峡谷和被高大树木遮挡. 伪距码系统间偏差可以通过先验标定进行改正或者参数化.已知先验载波系统间偏差,那么两个系统重叠频率的模糊度 ...

  8. [T-ARA][Apple is A]

    歌词来源:http://music.163.com/#/song?id=22704474 달콤달콤해 짜릿짜릿해 [tal-Kom-dal-Ko-mae jja-lid-jja-li-Tae] 반짝반 ...

  9. 浅谈MyBatis缓存

    在谈论MyBatis的缓存之前,我们先说说它的延迟加载,所谓延迟加载, resultMap中的association和collection标签具有延迟加载的功能.延迟加载的意思是说,在关联查询时,利用 ...

  10. JavaScript的DOM操作获取元素的大小

    通过 style 内联获取元素的大小 需要注意的是style 获取只能获取到行内 style 属性的 CSS 样式中的宽和高,如果有获取:如果没有则返回空. <!DOCTYPE html> ...