根据id来实现小程序tab切换,
本例根据绑定id来实现tab切换,但本例仍有缺陷,用for循环数据,无法实现切换。如有大神能够有更好方法,欢迎留言更正
WXML:
<view class="tab">
<view bindtap="tabs" class="{{tabArr.curHdIndex=='0'? 'active' : ''}}" id="0" data-id="0">tab-hd01</view>
<view bindtap="tabs" class="{{tabArr.curHdIndex=='1'? 'active' : ''}}" id="1" data-id="1">tab-hd02</view>
<view bindtap="tabs" class="{{tabArr.curHdIndex=='2'? 'active' : ''}}" id="2" data-id="2">tab-hd03</view>
<view bindtap="tabs" class="{{tabArr.curHdIndex=='3'? 'active' : ''}}" id="3" data-id="3">tab-hd04</view>
</view> <view class="tabcon">
<view class="{{tabArr.curBdIndex=='0'? 'active' : ''}}">tab-bd01111</view>
<view class="{{tabArr.curBdIndex=='1'? 'active' : ''}}">tab-bd02222</view>
<view class="{{tabArr.curBdIndex=='2'? 'active' : ''}}">tab-bd03333</view>
<view class="{{tabArr.curBdIndex=='3'? 'active' : ''}}">tab-bd04444</view>
</view>
WXSS:
.tab{
display: flex;
flex-direction:row;
height: 50px;
line-height: 50px;
}
.tab view{
width: 25%;
text-align: center;
}
.tab .active{
display: inline-block;
color: #188eee;
border-bottom: 1px #188eee solid;
}
.tabcon view{
display: none;
}
.tabcon .active{
display: inline-block;
}
JS
Page({
data: {
tabArr: {
curHdIndex: 0,
curBdIndex: 0,
}
},
tabs: function (e) {
var dataId = e.currentTarget.id;
var obj = {};
obj.curHdIndex = dataId;
obj.curBdIndex = dataId;
this.setData({
tabArr: obj
});
}
});
根据id来实现小程序tab切换,的更多相关文章
- 微信小程序tab切换,可滑动切换,导航栏跟随滚动实现
简介 看到今日头条小程序页面可以滑动切换,而且tab导航条也会跟着滚动,点击tab导航,页面滑动,切导航栏也会跟着滚动,就想着要怎么实现这个功能 像商城类商品类目如果做成左右滑动切换类目用户体验应该会 ...
- 小程序tab切换 点击左右滑动
wxml <scroll-view scroll-x="true" class="navbar-box"> <block wx:for=&qu ...
- 小程序——Tab切换
<view class="body"> <view class="nav bc_white"> <view class=" ...
- 小程序tab切换代码
<!--index.wxml--> <view class="container"> <view class="navtap" & ...
- 微信小程序Tab选项卡切换大集合
代码地址如下:http://www.demodashi.com/demo/14028.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- 小程序TAB列表切换内容动态变化,scrollview高度根据内容动态获取
滑动tab选项卡 一.在小程序里面tab选项卡是用的是自带的swiper组件,下面直接上代码 <view class="container"> <view cla ...
- 微信小程序tab(swiper)切换
<- wxml -> <view class="youhui"> <view ' bindtap='toggle'> 未使用 </view ...
- 微信小程序-tab标签栏实现教程
一.摘要 tab栏(标签切换栏)是app中常见的一种交互方式,它可以承载更多的内容,同时又兼顾友好体验的优点.但在小程序中,官方并没有为咱们提供现成的组件.因此我们程序员展现才艺的时候到了(其实市面上 ...
- 微信小程序 - tab选项卡(组件)
更新日期: 2019/3/5:首次发布,默认下标“curIndex”超出红色提示 2019/3/7:增加tabName,可自定义数据标题名称(详情看示例) 支持单个/多个tab(显示/隐藏) 参数: ...
随机推荐
- PHP 开发 api 接口安全验证
原文链接:http://blog.csdn.net/li741350149/article/details/62887524
- 20145324王嘉澜《网络对抗技术》MSF基础应用
实践目标 •掌握metasploit的基本应用方式 •掌握常用的三种攻击方式的思路. 实验要求 •一个主动攻击,如ms08_067 •一个针对浏览器的攻击,如ms11_050 •一个针对客户端的攻击, ...
- devicePixelRatio手机图片模糊的原因
一.移动设备图片模糊问题 手机上图片模糊问题原因就是一个像素在电脑上和手机上代表的实际像素的不同. 我们在样式表中使用的px(独立像素)单位其实并不一定代表着实际的一个像素(物理像素),这还要看硬件的 ...
- v-pre原样输出&&v-once只加载一次
html <div id="app"> <div v-pre>{{message1}}</div><!--原样输出--> <b ...
- UVa 12563 劲歌金曲(0-1背包)
https://vjudge.net/problem/UVA-12563 题意: 在一定的时间内连续唱歌,最后一首唱11分钟18秒的劲歌金曲,问最多能长多长时间. 思路: 0-1背包问题,背包容量为t ...
- Python matplot画散列图
同matlab一样,matplot也可画散列图scatter. import numpy as np import matplotlib.pyplot as plt #fig = plt.figure ...
- redis教程(The little redis book中文版)
许可证 <The Little Redis Book>是经由Attribution-NonCommercial 3.0 Unported license许可的,你不需要为此书付钱. 你可以 ...
- ROS编译时(catkin_make)找不到bullet,Could NOT find Bullet (missing: BULLET_DYNAMICS_LIBRARY
sudo apt-get install libbullet-dev
- python 将元组解析为多个参数
#create a tuple tuplex = , , print(tuplex) n1, n2, n3 = tuplex #unpack a tuple in variables print(n1 ...
- pandas (loc、iloc、ix)的区别
loc:通过行标签索引数据 iloc:通过行号索引行数据 ix:通过行标签或行号索引数据(基于loc和iloc的混合) 使用loc.iloc.ix索引第一行数据: loc: iloc: ix: