我是靠谱客的博主 暴躁黑裤,这篇文章主要介绍微信小程序之Tabs组件,现在分享给大家,希望可以做个参考。

知识点: 父向子传传值 子向父传值 样式激活
样式代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<Tabs tabs="{{tabs}}" currentIndex="{{currentIndex}}" bindchangeTabs='changeTabs'></Tabs> // 父 Page({ data: { tabs: [ { id: 0, title: '全部' },{ id: 1, title: '今日' },{ id: 2, title: '昨日' }, ], currentIndex: -1 }, changeTabs(e) { let {index} = e.detail this.setData({ currentIndex: index }) } })
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 子组件 <view class="tabs"> <view class="tabs_title"> <view wx:for="{{tabs}}" wx:key="index" data-index="{{item.id}}" class="tabs_item {{currentIndex === item.id? 'active' : ''}}" bindtap="changeTabs">{{item.title}}</view> </view> <view class="tabs_content"> <view hidden='{{currentIndex != 0}}'>页面1</view> <view hidden='{{currentIndex != 1}}'>页面2</view> <view hidden='{{currentIndex != 2}}'>页面3</view> </view> </view> // css .tabs_title { display: flex; text-align: center; align-items: center; } .tabs_item { flex: 1; padding: 10rpx; border-bottom: 1px solid #fff; } .active { border-bottom: 1px solid brown; } // js Component({ properties: { tabs: { type: Array, value: [] }, currentIndex: { type: Number, }, }, methods: { changeTabs(e) { let { index } = e.currentTarget.dataset this.triggerEvent('changeTabs', {index}) }, } })

最后

以上就是暴躁黑裤最近收集整理的关于微信小程序之Tabs组件的全部内容,更多相关微信小程序之Tabs组件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部