uniapp导航栏切换且滑动

<template>
	<view>
		我的
		<scroll-view scroll-x="true" class="scroll-content" :scroll-into-view="scrollIintoIndex">
			<view :id="'top' + index" v-for="(item,index) in topBar" :key="index" class="scroll-item" @tap="changeTabIndex(index)">
				<text :class="topBarIndex === index ? 'f-active-color' : 'f-color'">{{item.name}}</text>
			</view>
		</scroll-view>
		<!--   -->
		<swiper @change="onChangeTab" :current="topBarIndex" :style="'height:' + clentHeight + 'px;'">
			<swiper-item v-for="(item,index) in topBar" style="animation-delay: 2s;">
				<view class="swiper-item" v-if="topBarIndex === 0">
					<Card cardTitle="你好列表"></Card>
					<Banner></Banner>
					<Icons></Icons>
					<Card cardTitle="热销爆品"></Card>
					<Hot></Hot>
				</view>
				<view class="swiper-item" v-if="topBarIndex === 1">
					<Icons></Icons>
					<Card cardTitle="热销爆品"></Card>
					<Hot></Hot>
				</view>
				<view class="swiper-item" v-if="topBarIndex === 3">
					<Card cardTitle="你好列表"></Card>
					<Banner></Banner>
					<Icons></Icons>
					<Card cardTitle="热销爆品"></Card>
					<Hot></Hot>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import Card from '@/components/common/Card.vue'
	import Banner from '@/components/index/Banner.vue'
	import Icons from '@/components/index/Icons.vue'
	import Hot from '@/components/index/Hot.vue'
	export default {
		components:{
			Card,
			Banner,
			Icons,
			Hot,
		},
		data() {
			return {
				// 选中的索引
				topBarIndex: 0,
				scrollIintoIndex:'top0',
				
				// 获取内容高度
				clentHeight:'',
				// 数据
				topBar:[
					{name:'推荐'},
					{name:'关注'},
					{name:'体育'},
					{name:'热点'},
					{name:'财经'},
					{name:'娱乐'},
					{name:'历史'},
					{name:'家具数码'},
				]
			}
		},
		onLoad() {
			if(!uni.getStorageSync('token_aianxing')) {
				uni.navigateTo({
					url:'/pages/login/login'
				})
			}
		},
		onReady() {
			let view = uni.createSelectorQuery().select(".swiper-item")
			view.boundingClientRect(data => {
				this.clentHeight = data.height
			}).exec();
		},
		methods: {
			// 推荐切换
			changeTabIndex(index) {
				if(this.topBarIndex === index) {
					return;
				}
				this.topBarIndex = index
				this.scrollIintoIndex = 'top' + index
			},
			// 内容切换
			onChangeTab(e) {
				this.changeTabIndex(e.detail.current)
			}
		}
	}
</script>

<style lang="scss" scoped>
.scroll-content {
	width: 100%;
	height: 80rpx;
	white-space: nowrap;
	animation-delay: 2s;
	.scroll-item {
		display: inline-block;
		padding: 10rpx 30rpx;
		font-size: 36rpx;
		animation-delay: 2s;
	}
	.f-active-color {
		padding: 10rpx 0;
		border-bottom: 6rpx solid ;
		animation-delay: 2s;
	}
}
</style>

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
UniApp中,通过使用Swiper组件可以实现头部导航栏滑动效果。首先,在app.vue文件中引入全局样式,可以在其中设置导航栏的样式和布局。可以通过设置组件内部CSS开启导航栏底部阴影效果。接下来,可以结合Swiper组件来实现头部导航栏滑动切换效果。Swiper组件可以用于创建可滑动的视图容器,可以配合导航栏标签页的切换,实现用户在页面之间的滑动切换。这样可以实现更好的效果。所以,通过设置导航栏的样式和布局以及使用Swiper组件,可以实现UniApp头部导航栏滑动效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uniapp常用组件——顶部导航选项栏(可滑动)](https://blog.csdn.net/poppingJ/article/details/108361892)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [uni-app顶部导航(可滑动)](https://blog.csdn.net/maoge_666/article/details/129952640)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [TCPView 是一个 Windows 程序,它将显示系统上所有 TCP 和 UDP 终结点的详细列表,包括 tcp 连接](https://download.csdn.net/download/fyq158797/88280042)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值