uniapp组件-uni-segmented-control分段器

本文介绍了一个uni-segmented-control组件的使用示例,通过不同样式类型的选项卡展示了如何通过点击事件切换选项卡内容。代码中包含了按钮样式和文本样式的选项卡,并演示了如何设置选项卡的背景颜色及点击事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方示例:https://ext.dcloud.net.cn/plugin?id=54 

效果图:

代码实现:

<template>
	<view>
		<view>
			<uni-segmented-control :current="current" :values="items" style-type="button" active-color="#dd524d" @clickItem="onClickItem" />
		</view>
		<view class="uni-padding-wrap uni-common-mt">
			<uni-segmented-control :current="current" :values="items" style-type="text" active-color="#007aff" @clickItem="onClickItem" />
		</view>
		<view style="padding: 0px 30px;margin-top: 30px;">
			<uni-segmented-control :current="current" :values="items" style-type="button" active-color="#4cd964" @clickItem="onClickItem" />
		</view>
		<view>
			<uni-segmented-control :current="current" :values="items" style-type="text" active-color="#4cd964" @clickItem="onClickItem" />
		</view>

	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				items: ['选项卡1', '选项卡2', '选项卡3'],
				current: 0,
			}
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			}
		}
	}
</script>

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值