uni-app选项卡组件

<template>
	<view class="tab">
		<scroll-view scroll-x="true" class="tab-scroll">
			<view class="tab-scroll-box">
				<view class="tab-scroll-box-item" :class="{active:activeIndex===index}" @click="clickTab(item,index)"
					v-for="(item,index) in list" :key="index">
					{{item.name}}
				</view>
			</view>
		</scroll-view>
		<view class="tab-icon">
			<uni-icons type="gear" size="26" color="#666"></uni-icons>
		</view>
	</view>
</template>

<script>
	export default {
		name: "tab",
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			}
		},
		created() {
			console.log(this.list);
		},
		data() {
			return {
				activeIndex: 0
			};
		},
		methods: {
			clickTab(item, index) {
				this.activeIndex = index
				this.$emit('tab', {
					item,
					index
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab {
		display: flex;
		background-color: #FFFFFF;
		border-bottom: 1px solid #f5f5f5;
		width: 100%;

		.tab-scroll {
			// flex: 1;
			overflow: hidden;

			.tab-scroll-box {
				display: flex;
				// 垂直居中
				align-items: center;
				// flex-wrap: nowrap;
				height: 45px;

				.tab-scroll-box-item {
					// 控制元素的缩小比例,
					flex-shrink: 0;
					font-size: 16px;
					color: #333333;
					padding: 0 10px;

					&.active {
						color: $mk-base-color;
					}
				}
			}
		}

		.tab-icon {
			position: relative;
			display: flex;
			// 水平居中
			justify-content: center;
			// 垂直居中
			align-items: center;
			width: 45px;

			// 伪类
			&::after {
				content: '';
				position: absolute;
				top: 12px;
				bottom: 12px;
				left: 0;
				width: 1px;
				background-color: #ddd;
			}
		}
	}
</style>

使用

		<!-- 自定义选项卡组件 -->
		<tab :list='labelList' @tab='tab'></tab>

		onLoad() {
			this.getLabel()
		},
		methods: {
			getLabel() {
				this.$api.getLabel().then(res => {
					this.labelList = res.data
				})
			},
			tab({item,index}) {
				console.log(item, index);
			}
		}

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值