基于uniapp的简单自定义公共组件mz-header-tab-tab

30 篇文章 4 订阅

基于uniapp的简单自定义公共组件-tab切换

效果实例

在这里插入图片描述
在这里插入图片描述

自定义组件mz-header-tab

<template>
	<view class="matchHeader-status">
		<template v-for="(item,index) in list">
			<view :key="index" class="matchHeader-statusItems" :class="{currentMatchStatus:item.code==code}"
				@click="switchTabHandle(item)">
				<text class="matchHeader-name" :style="{'fontSize':fontSize}">{{item.name}}</text>
				<text class="select-line"></text>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		name: "mz-header-tab",
		props: {
			code: {
				type: String,
				default: () => {
					return ''
				}
			},
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			fontSize: {
				type: String,
				default: () => {
					return '14px'
				}
			}
		},
		data() {
			return {

			};
		},
		methods: {
			/**
			 * tab切换
			 * **/
			switchTabHandle(e) {
				this.$emit("change", e)
			}
		}
	}
</script>

<style lang="scss" scoped>
	//状态栏
	.matchHeader-status {
		height: 40px;
		width: 100%;
		display: flex;
		flex-direction: row;
		white-space: nowrap;
		overflow-x: auto;

		.matchHeader-statusItems {
			margin-left: 22px;
			position: relative;

			.matchHeader-name {
				font-size: 14px;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #999;
			}
		}

		.matchHeader-statusItems:first-child {
			margin-left: 4px;
		}

		.currentMatchStatus {
			position: relative;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.matchHeader-name {
				transform: scale(1.1);
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #FF792A;
				margin-top: -2px;
			}

			.select-line {
				width: 25px;
				height: 3px;
				background: #FF792A;
				border-radius: 1px;
				margin-top: 12px;
				display: block;
			}
		}
	}
</style>

使用案例

<template>
	<view class="orderManage-wrap">
		<!-- 状态栏 -->
		<view class="orderManage-tab">
			<view style="height: 10px;"></view>
			<mz-header-tab :list="tabList" :code="code" @change="tabChangeHandle">
			</mz-header-tab>
		</view>
		<view style="height: 54px;"></view>
		<!-- 订单列表-start -->
		<view class="orderManage-list">
			
		</view>
		<!-- 订单列表-end -->
	</view>
</template>

<script>
	
	export default {
		components: {
			
		},
		data() {
			return {
				code: '-2', //当前显示tab
				tabList: [{
						id: 0,
						name: '全部订单',
						code: '-2'
					},
					{
						id: 1,
						name: '待付订单',
						code: '0'
					},
					{
						id: 2,
						name: '已全额支付',
						code: '1'
					},
					{
						id: 3,
						name: '待收货',
						code: '5'
					},
					{
						id: 4,
						name: '已收货',
						code: '6'
					},
					{
						id: 5,
						name: '退款',
						code: '3'
					}
				]
			};
		},
		onLoad() {

		},
		onShow() {

		},
		methods: {
			/**
			 * tab切换
			 * **/
			tabChangeHandle(params) {
				console.log(params)
				this.code = params.code;
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.orderManage-wrap {
		width: $mzWidth;
		margin: 12px auto;
		display: flex;
		flex-direction: column;
	}

	//tab
	.orderManage-tab {
		width: $mzWidth;
		height: 54px;
		position: fixed;
		left: 4.265%;
		right: 4.265%;
		top: 0px;
		z-index: 5;
		background-color: #F2F2F2;
	}

	//订单列表
	.orderManage-list {
		width: 100%;
		margin: 0px auto;
		display: flex;
		flex-direction: column;
	}
</style>

<view style="border: 1px solid blue;width: 91.47%;margin: 24px auto;height: 70px;">
			<scroll-view scroll-x="true" style="width: 100%;height: 70px;white-space: nowrap;">
				<view style="height: 50px;border: 1px solid red;margin-right: 24px;display: inline-block;">1受恶意</view>
				<view style="height: 50px;border: 1px solid red;margin-right: 24px;display: inline-block;">2加油</view>
				<view style="height: 50px;border: 1px solid red;margin-right: 24px;display: inline-block;">3水电费水电费
				</view>
				<view style="height: 50px;border: 1px solid red;margin-right: 24px;display: inline-block;">4水电费水电费
				</view>
				<view style="height: 50px;border: 1px solid red;margin-right: 24px;display: inline-block;">5新闻</view>
				<view style="height: 50px;border: 1px solid red;margin-right: 24px;display: inline-block;">6资讯</view>
			</scroll-view>
		</view>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值