uniapp 页面顶部选项卡

<template>
	<!-- 顶部选项卡 -->
	<view class="tabs">
		<view 
			class="uni-tab-item" 
			v-for="(tab,index) in tabBars"
			:key="tab.id"
		>
			<text 
				class="uni-tab-item-title"
				:class="{tabActive: tabIndex==tab.id}"
				@click="tarTap(tab)"
			>
				{{tab.name}}
			</text>
		</view>
	</view>
</template>
 
<script>
	export default {
		name: "index-tabbar",
		props:{
			tabBars: Array,
			tabIndex: String
		},
		data(){
			return {
				
			}
		},
		methods:{
			tarTap(item){
				this.$emit("TarTap",item)
			}
		}
	}
</script>
 
<style lang="scss">
	.tabs{
		display: flex;
		flex: 1;
		flex-direction: row;
		overflow-x: scroll;
		height: 100%;
	}
	.uni-tab-item{
		white-space: nowrap;
		line-height: 110rpx;
		height: 110rpx;
	}
	.uni-tab-item-title{
		color: #909399;
		font-size: 32rpx;
		width: 150rpx;
		height: 80rpx;
		line-height: 70rpx;
		display: inline-block;
		text-align: center;
	}
	.tabActive{
		color: #21A78A;
	}
	// 选中后下方横杠
	.tabActive::after {
	    content: '';
	    width: 40%;
	    height: 2rpx;
	    display: block;
	    margin: 0 auto;
	    border-bottom: 4rpx solid #21A78A;
	}

</style>

调用

HTML部分   

		<view>
			<index-tabbar :tabBars="tabBars" @TarTap="TarData" :tabIndex="tabIndex"></index-tabbar>
		</view>
		<view>
             <!-- tabbars组件 -->
			<Assign v-if="currentTabComponent=='Assign'" :tasklist='tasklist'></Assign>
			<Plaza v-else-if="currentTabComponent=='Plaza'" :tasklist='tasklist'></Plaza>
		</view>

JavaScript部分  

    import indexTabbar from '@/pages/task/company/component/topBar.vue';
	import Assign from '@/pages/task/company/component/assign.vue';
	import Plaza from '@/pages/task/company/component/plaza.vue';
	export default {
		data() {
			return {
				tabIndex: "Assign", // 当前tab
				tabBars: [{
						name: "指派单",
						id: "Assign"
					},
					{
						name: "广场单",
						id: "Plaza"
					}
				], // 任务栏列表
				currentTabComponent: "Assign", // 当前组件
			};
		},
		components: {
			indexTabbar,
			Assign,
			Plaza
		},
		beforeCreate() {
			uni.showLoading({
				title: '正在加载中...',
			})
		},
		onPullDownRefresh() {
            // 下拉刷新时执行的方法
			this.refreshList() // 重新获取页面数据
			uni.stopPullDownRefresh(); //停止刷新
		},
		mounted() {
			setTimeout(() => {
				uni.hideLoading()
			}, 500)
		},
		methods:{
			// 刷新任务列表
			refreshList() {
				if (this.tabIndex == 'Assign') {
					this.param.taskType= '1' ;
					receiveTask(this.param).then(res => {
						this.tasklist = JSON.parse(JSON.stringify(res.data.data));
						return this.tasklist
					})
			
				} else if (this.tabIndex == 'Plaza') {
					this.param.taskType= '0' ;
					receiveTask(this.param).then(res => {
						this.tasklist = JSON.parse(JSON.stringify(res.data.data));
						return this.tasklist
					})
				} 
			},
			// 点击tab标签
			TarData(item) {
				//设置id,来显示选中那个标签,显示下划线
				this.tabIndex = item.id;
				//显示标签对应的组件内容
				this.currentTabComponent = item.id
			},
		},
	}

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值