uniapp头部导航加滑动切换

本文展示了一个使用Vue.js实现的滑动切换组件和导航栏联动的示例。通过`v-for`指令动态渲染导航条目,利用`v-if`和`v-show`控制选中状态,同时监听`swiper`的`change`事件来更新导航栏。代码中详细定义了样式以达到预期的视觉效果,包括导航条目的激活样式和底部指示条。此示例适用于前端开发中的交互设计和页面动态效果构建。
摘要由CSDN通过智能技术生成
<template>
	<view>
		<view class="nav">
			<view v-for="(item,index) in titleList" :key="index" class="navEach">
				<view @click="changeTitle(index)">
					<view :class="item.istrue?'navNameActive':'navName'">{{item.name}}</view>
					<view class="navBottom"><view class="navActvie" v-show="item.istrue"></view></view>
				</view>
			</view>
		</view>
		
		<swiper class="swiperbox" :current="currentIndex" @change="changeCurrent">
			<swiper-item>开拍提醒</swiper-item>
			<swiper-item>飞洒发</swiper-item>
			<swiper-item>151</swiper-item>
			<swiper-item>sd23发送</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				//头部导航
				titleList:[
					{name:"开拍提醒",istrue:true},
					{name:"中拍",istrue:false},
					{name:"被超越",istrue:false},
					{name:"已领先",istrue:false},
				],
				currentIndex:0,//当前滑块
			}
		},
		methods:{
			//滑块改变
			changeCurrent(e){
				this.changeTitle(e.detail.current);
			},
			//头部切换
			changeTitle(e){
				//防止多次执行
				if(e !== this.currentIndex){
					this.titleList[this.currentIndex].istrue = false;//改变旧的
					this.currentIndex = e;//滑块切换
					this.titleList[e].istrue = true;//改变新的
				}
			}
		}
	}
</script>

<style scoped>
	.nav{
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 70rpx;
		display: flex;
		align-items: center;
	}
	.navEach{
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.navNameActive{
		font-size: 28rpx;
		color: #C42A2A;
		font-weight: 550;
	}
	.navName{
		font-size: 28rpx;
		color: #aaa;
	}
	.navBottom{
		width: 100%;
		display: flex;
		justify-content: center;
		height: 8rpx;
	}
	.navActvie{
		width: 56rpx;
		height: 4rpx;
		background-color: #C42A2A;
		border-radius: 1px;
		margin-top: 4rpx;
	}
	
	.swiperbox{
		position: absolute;
		top: 76rpx;
		left: 0;
		width: 100%;
		height: calc(100% - 76rpx);
		background-color: #2F86F6;
	}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值