通过uni-ui库实现滑动选项卡切换tab页,一般用于app上

该文展示了如何利用swiper组件在Vue.js中创建选项卡切换功能。通过数据绑定和事件监听,可以改变swiper的当前索引,从而切换不同的swiper-item内容。同时,文章包含了动态样式应用和点击事件处理方法。
摘要由CSDN通过智能技术生成

原理是通过 swiper 组件来实现,通过事件对象切换索引即可

swiper-item则是每个选项卡。实例代码

<template>
	<view>
		
		<view class="myTabs" style="display: flex; flex-direction: row; justify-content: space-around;">
			<view :key="0" :class="{'activedTab':activedTab == 0}" @click="activedTab = 0">
				第一类
			</view>
			<view :key="1" :class="{'activedTab':activedTab == 1}" @click="activedTab = 1">
				第二类
			</view>
		</view>
		
		<view style="height: 60rpx; background-color: #A5A5A5;">
			
		</view>
		
		<swiper :current="activedTab" :autoplay="false" :duration="300" @change="changeContentBox">
			<swiper-item>
				<view>
					第一屏内容 
				</view>
				<view>
					当前activedTab =  {{activedTab}}
				</view>
			</swiper-item>
			
			
			<swiper-item>
				<view>
					第二屏内容 
				</view>
				<view>
					当前activedTab =  {{activedTab}}
				</view>
			</swiper-item>
		</swiper>
		
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				activedTab: 0
			}
		},
		methods: {
			changeContentBox(e){
				this.activedTab = e.detail.current
			}
		},
		onLoad () {
			
		}
	}
</script>
 
<style>
	.activedTab {
		font-size: 50rpx;
		color: red;
		font-weight: bold;
	}
</style>

样式自己修改

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值