uniapp实现tabs切换(可滑动)效果实例

 更新时间:2023年07月21日 08:32:09   作者:wmao  
这篇文章主要给大家介绍了关于uniapp实现tabs切换(可滑动)效果的相关资料,tabs切换无论是在app端还是小程序或者H5页面都是很常见的功能,文中通过实例代码介绍的很详细,需要的朋友可以参考下

uniapp实现tabs切换(可滑动)

<template>
	<view class="body-view">
		<!-- 使用scroll-view实现tabs滑动切换 -->
		<scroll-view class="top-menu-view" scroll-x="true" :scroll-into-view="tabCurrent">
			<view class="menu-topic-view" v-for="item in tabs" :id="'tabNum'+item.id" :key="(item.id - 1)" @click="swichMenu(item.id - 1)">
				<view :class="currentTab==(item.id - 1) ? 'menu-topic-act' : 'menu-topic'">
					<text class="menu-topic-text">{{item.name}}</text>
					<view class="menu-topic-bottom">
						<view class="menu-topic-bottom-color"></view>
					</view>
				</view>
			</view>
		</scroll-view>
		<!-- 内容 -->
		<swiper class="swiper-box-list" :current="currentTab" @change="swiperChange">
			<swiper-item class="swiper-topic-list" v-for="item in swiperDateList" :key="item.id">
				<view class="swiper-item">
					{{item.content}}
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tabs: [{
						id: 1,
						name: '推荐'
					},
					{
						id: 2,
						name: '交通交通'
					},
					{
						id: 3,
						name: '住房'
					},
					{
						id: 4,
						name: '社会保障'
					},
					{
						id: 5,
						name: '民生热点'
					},
					{
						id: 6,
						name: '即日头条'
					},
					{
						id: 7,
						name: '新闻联播'
					},
				],
				currentTab: 0,
				tabCurrent: 'tabNum1',
				// Tab切换内容
				swiperDateList: [{
						id: 1,
						content: '推荐'
					},
					{
						id: 2,
						content: '交通交通'
					},
					{
						id: 3,
						content: '住房'
					},
					{
						id: 4,
						content: '社会保障'
					},
					{
						id: 5,
						content: '民生热点'
					},
					{
						id: 6,
						content: '即日头条'
					},
					{
						id: 7,
						content: '新闻联播'
					},
				],
			}
		},
		onLoad() {
		},
		methods: {
			swichMenu(id) {
				this.currentTab = id
				console.log(11,id)
				this.tabCurrent = 'tabNum'+ id
			},
			swiperChange(e) {
				console.log(22,e.detail.current)
				let index = e.detail.current
				this.swichMenu(index)
			}
		}
	}
</script>
<style scoped lang="scss">
	.body-view {
		height: 100vh;
		width: 100%;
		display: flex;
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		align-items: flex-start;
		justify-content: center;
	}
	.top-menu-view {
		display: flex;
		position: fixed;
		top: 100rpx;
		left: 0;
		white-space: nowrap;
		width: 100%;
		background-color: #FFFFFF;
		height: 86rpx;
		line-height: 86rpx;
		border-top: 1rpx solid #d8dbe6;
		.menu-topic-view {
			display: inline-block;
			white-space: nowrap;
			height: 86rpx;
			position: relative;
			.menu-topic-text {
				font-size: 30rpx;
				color: #303133;
				padding: 10rpx 40rpx;
			}
			// .menu-topic-act {
			// 	margin-left: 30upx;
			// 	margin-right: 10upx;
			// 	position: relative;
			// 	height: 100%;
			// 	display: flex;
			// 	align-items: center;
			// 	justify-content: center;
			// }
			.menu-topic-bottom {
				position: absolute;
				bottom: 0;
				width: 100%;
				.menu-topic-bottom-color {
					width: 40rpx;
					height: 4rpx;
				}
			}
			.menu-topic-act .menu-topic-bottom {
				display: flex;
				justify-content: center;
			}
			.menu-topic-act .menu-topic-bottom-color {
				background: #3d7eff;
			}
		}
	}
	.swiper-box-list {
		width: 100%;
		padding-top: 200rpx;
		flex:1;
		background-color: #FFFFFF;
		.swiper-topic-list {
		     width: 100%;
		 }
	}
</style>

继续加油呀~

到此这篇关于uniapp实现tabs切换(可滑动)效果的文章就介绍到这了,更多相关uniapp实现tabs切换内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • JavaScript中的location、history、navigator对象实例介绍

    JavaScript中的location、history、navigator对象实例介绍

    这篇文章主要介绍了JavaScript中的location、history、navigator对象实例介绍,需要的朋友可以参考下
    2023-05-05
  • 对于js垃圾回收机制的理解

    对于js垃圾回收机制的理解

    下面小编就为大家带来一篇对于js垃圾回收机制的理解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • JS限制输入框输入的实现代码

    JS限制输入框输入的实现代码

    这篇文章主要介绍了JS限制输入框输入的实现代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-07-07
  • BootStrap table实现表格行拖拽效果

    BootStrap table实现表格行拖拽效果

    这篇文章主要为大家详细介绍了BootStrap table实现表格行拖拽效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-12-12
  • Avalonjs双向数据绑定与监听的实例代码

    Avalonjs双向数据绑定与监听的实例代码

    本文通过实例代码给大家介绍了Avalonjs双向数据绑定与监听的实现代码,非常不错,具有参考借鉴价值,需要的的朋友参考下吧
    2017-06-06
  • 原生JS实现的轮播图功能详解

    原生JS实现的轮播图功能详解

    这篇文章主要介绍了原生JS实现的轮播图功能,结合实例形式分析了javascript实现轮播图的原理、操作技巧与相关注意事项,需要的朋友可以参考下
    2018-08-08
  • 使用Mock.js生成前端测试数据

    使用Mock.js生成前端测试数据

    这篇文章主要介绍了使用Mock.js生成前端测试数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-12-12
  • JavaScript封装Vue-Router实现流程详解

    JavaScript封装Vue-Router实现流程详解

    这篇文章主要介绍了JavaScript封装Vue-Router实现流程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-09-09
  • 原生JavaScript实现的简单放大镜效果示例

    原生JavaScript实现的简单放大镜效果示例

    这篇文章主要介绍了原生JavaScript实现的简单放大镜效果,涉及javascript事件响应及页面元素属性动态操作相关实现技巧,需要的朋友可以参考下
    2018-02-02
  • JavaScript中获取当前时间yyyymmddhhmmss的六种实现方式

    JavaScript中获取当前时间yyyymmddhhmmss的六种实现方式

    js中提供了一个Date对象供我们获取当前时间,下面这篇文章主要给大家介绍了关于JavaScript中获取当前时间yyyymmddhhmmss的六种实现方式,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2023-12-12

最新评论