uniapp tab自定义 同步选择

js yekong

uniapp tab自定义 同步选择

使用

<tabLine :list="tablist" :active.sync="active"></tabLine>
tablist: [{
	name: '全部',
	id: -1
}, {
	name: '未回复',
	id: 1
}, {
	name: '已回复',
	id: 0
}],
active: -1,

代码

<template>
	<div class="tabs">
		<div class="tab cur" :class="{active:active==item.id}" @click="getactive(item.id)" v-for="(item,index) in list"
			:key="index"><span>{{ item.name }}</span>
			<div class="line"></div>
		</div>
	</div>
</template>

<script>
	export default {
		name: "tabs",
		props: {
			list: {
				type: Array,
				default () {
					return [];
				}
			},
			active: {
				type: Number,
				default () {
					return 0;
				}
			},
		},
		methods: {
			getactive(e) {
				this.$emit('update:active', e)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.tabs {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		width: 750rpx;
		margin: auto;

		.tab {
			display: flex;
			justify-content: center;
			align-items: center;
			flex-wrap: nowrap;
			flex-direction: column;
			flex: 1;
			position: relative;
			height: 100rpx;

			span {
				font-size: 30rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #646A73;
			}

			.line {
				background: rgba(54, 107, 229, 0);
				border-radius: 4rpx;
				position: absolute;
				bottom: 1rpx;
				width: 100%;
				height: 4rpx;
			}
		}

		.tab.active {
			span {
				color: #7698FF;
			}

			.line {
				background: #4877FF;
			}
		}
	}
</style>

喜欢