uniapp tab样式自定义

uniapp yekong 1033℃

uniapp 微信小程序开发时,需要实现tab自定义效果。将实现代码记录一下,留待复用。
uniapp tab样式自定义

使用实例

uniapp 微信小程序 案例 遇见美家美户

使用实例

<tabLine :list="tablist" :active.sync="active"></tabLine>
tablist: [{
					name: '在卖',
					id: 0,
					num: 2
				}, {
					name: '草稿',
					id: 1,
					num: 2
				}, {
					name: '已下架',
					id: 2,
					num: 0
				}, {
					name: '积分',
					id: 3,
					num: 0
				}],
				active: 0,

代码

/**
* @Author: 858834013@qq.com
* @Name: tabs
* @Date: 2022-06-29
* @Desc: tabs https://www.wanjunshijie.com/note/uniapp/3096.html
<tabLine :list="tablist" :active.sync="active"></tabLine>
*/
<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">
			<div class="titles"><span class="title">{{ item.name }}</span>
				<div class="info"><span class="dian" v-if="item.num">.</span><span v-if="item.num"
						class="num">{{item.num}}</span></div>
			</div>
			<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;
			position: relative;
			height: 90rpx;
			margin-left: 30rpx;
			margin-right: 50rpx;

			.titles {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				flex-wrap: nowrap;
				flex-direction: row;
				align-content: flex-start;

				.title {
					font-size: 28rpx;
					color: #333333;
					font-weight: 400;
				}

				.num {
					font-size: 28rpx;
					color: #333333;
					font-weight: 400;
				}

				.dian {
					font-size: 28rpx;
					color: #333333;
					font-weight: 400;
					height: 20rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-wrap: nowrap;
					flex-direction: row;
					align-content: flex-start;
					padding-bottom: 15rpx;
					margin-left: 5rpx;
					margin-right: 5rpx;
				}

			}

			.line {
				background: rgba(54, 107, 229, 0);
				position: absolute;
				bottom: 1rpx;
				width: 50rpx;
				height: 6rpx;
			}
		}

		.tab.active {

			.title {
				font-family: PingFangSC-Medium;
				font-size: 36rpx;
				color: #333333;
				letter-spacing: -0px;
				font-weight: 500;
			}

			.dian {
				font-size: 36rpx;
				color: #333333;
				font-weight: 500;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-wrap: nowrap;
				flex-direction: row;
				align-content: flex-start;
				padding-bottom: 15rpx;
				margin-left: 5rpx;
				margin-right: 5rpx;
			}

			.num {
				font-family: PingFangSC-Medium;
				font-size: 36rpx;
				color: #333333;
				font-weight: 500;

			}

			.line {
				background: #EF4034;
			}
		}
	}

	.info {
		position: absolute;
		left: 100%;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: nowrap;
		flex-direction: row;
		align-content: flex-start;
	}
</style>

喜欢 (0)