uniapp左侧分类右侧内容,滑动右侧到底部再次滑动切换下个分类

时间: 2023-11-07 17:30:25 浏览: 36
这个功能可以通过以下步骤实现: 1. 在左侧分类列表中,绑定一个点击事件,当用户点击某个分类时,获取该分类对应的内容列表,并将其展示在右侧内容区域。 2. 在右侧内容区域中,监听滚动事件,当用户滑动到底部时触发一个回调函数。 3. 在回调函数中,判断当前显示的内容列表是否已经加载完毕,如果没有加载完毕,则继续加载下一页数据,并将新的数据追加到已有数据的末尾;如果已经加载完毕,则切换到下一个分类的内容列表。
相关问题

uniapp左侧分类右侧内容,滑动右侧到底部再次滑动切换下个分类代码

以下是一个简单的实现,仅供参考: <template> <view class="container"> <view class="left"> <scroll-view scroll-y="true" class="left-scroll" :scroll-into-view="activeIndex" :scroll-with-animation="true"> <view v-for="(item, index) in categoryList" :key="index" :class="['left-item', activeIndex === index ? 'active' : '']" @click="changeActive(index)"> {{ item }} </view> </scroll-view> </view> <view class="right"> <scroll-view scroll-y="true" class="right-scroll" :scroll-into-view="activeContentId" :scroll-with-animation="true" @scrolltolower="loadMore"> <view v-for="(item, index) in currentContentList" :key="item.id" class="right-item"> {{ item.title }} </view> <view v-if="loading" class="loading">加载中...</view> <view v-if="!loading && noMore" class="no-more">已经到底了</view> </scroll-view> </view> </view> </template> <script> export default { data() { return { categoryList: ['分类1', '分类2', '分类3'], contentList: [ { id: 1, title: '内容1', category: '分类1' }, { id: 2, title: '内容2', category: '分类1' }, { id: 3, title: '内容3', category: '分类2' }, { id: 4, title: '内容4', category: '分类2' }, { id: 5, title: '内容5', category: '分类3' }, { id: 6, title: '内容6', category: '分类3' }, ], activeIndex: 0, activeContentId: '', currentContentList: [], loading: false, noMore: false, pageSize: 10, pageIndex: 0, } }, mounted() { this.loadMore() }, methods: { changeActive(index) { this.activeIndex = index this.pageIndex = 0 this.activeContentId = '' this.currentContentList = this.getContentList() this.loadMore() }, getContentList() { const category = this.categoryList[this.activeIndex] return this.contentList.filter(item => item.category === category) }, loadMore() { if (this.loading || this.noMore) { return } this.loading = true setTimeout(() => { const contentList = this.getContentList() const startIndex = this.pageIndex * this.pageSize const endIndex = startIndex + this.pageSize const newData = contentList.slice(startIndex, endIndex) this.currentContentList = this.currentContentList.concat(newData) this.pageIndex += 1 this.loading = false if (endIndex >= contentList.length) { this.noMore = true } if (this.currentContentList.length > this.pageSize * 3) { // 如果当前显示的内容太多了,可以通过滚动到底部自动切换到下一个分类 uni.pageScrollTo({ scrollTop: 9999, duration: 300, complete: () => { this.changeActive(this.activeIndex + 1 >= this.categoryList.length ? 0 : this.activeIndex + 1) }, }) } }, 1000) }, }, } </script> <style> .container { display: flex; flex-direction: row; height: 100vh; } .left { width: 120rpx; background-color: #eee; } .left-scroll { height: 100%; } .left-item { height: 80rpx; line-height: 80rpx; text-align: center; } .left-item.active { background-color: #fff; } .right { flex: 1; background-color: #fff; } .right-scroll { height: 100%; padding: 20rpx; } .right-item { height: 80rpx; line-height: 80rpx; text-align: center; border-bottom: 1px solid #eee; } .loading, .no-more { height: 80rpx; line-height: 80rpx; text-align: center; color: #999; } </style>

uniapp左右滑动切换内容

在Uniapp中,可以使用`swiper`组件实现左右滑动切换内容的效果。具体实现步骤如下: 1. 在页面中引入`swiper`组件: ```html <swiper> <swiper-item> <!-- 第一页内容 --> </swiper-item> <swiper-item> <!-- 第二页内容 --> </swiper-item> ... </swiper> ``` 2. 在`swiper`组件中添加`indicator-dots`属性,使得可以显示分页指示器: ```html <swiper indicator-dots> <swiper-item> <!-- 第一页内容 --> </swiper-item> <swiper-item> <!-- 第二页内容 --> </swiper-item> ... </swiper> ``` 3. 可以使用`current`属性来控制当前显示的页数,通过左右滑动来改变`current`属性的值: ```html <swiper indicator-dots :current="current"> <swiper-item> <!-- 第一页内容 --> </swiper-item> <swiper-item> <!-- 第二页内容 --> </swiper-item> ... </swiper> ``` ```js export default { data() { return { current: 0 // 当前显示的页数 }; }, methods: { // 滑动切换页面时触发 swiperChange(event) { this.current = event.detail.current; } } }; ``` 完整代码示例: ```html <template> <view> <swiper indicator-dots :current="current" @change="swiperChange"> <swiper-item> <view class="page1"> <text>第一页</text> </view> </swiper-item> <swiper-item> <view class="page2"> <text>第二页</text> </view> </swiper-item> <swiper-item> <view class="page3"> <text>第三页</text> </view> </swiper-item> </swiper> </view> </template> <script> export default { data() { return { current: 0 // 当前显示的页数 }; }, methods: { // 滑动切换页面时触发 swiperChange(event) { this.current = event.detail.current; } } }; </script> <style scoped> .page1 { background-color: #f00; height: 100vh; } .page2 { background-color: #0f0; height: 100vh; } .page3 { background-color: #00f; height: 100vh; } </style> ```

相关推荐

最新推荐

recommend-type

微信小程序左右滑动切换页面详解及实例代码

主要介绍了微信小程序左右滑动切换页面详解及实例代码的相关资料,需要的朋友可以参考下
recommend-type

Android仿抖音上下滑动布局

主要为大家详细介绍了Android仿抖音上下滑动布局,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

Android实现界面左右滑动切换功能

相信大家一定都使用过手机QQ和微信之类的软件,当我们使用时不难发现其界面的切换不仅可以通过点击页标签来实现,还可以通过左右滑动来实现的,下面小编给大家介绍下如何实现这个功能
recommend-type

js实现移动端tab切换时下划线滑动效果

主要为大家详细介绍了js实现移动端tab切换时下划线滑动效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

Android自定义控件ScrollView实现上下滑动功能

主要为大家详细介绍了Android自定义控件ScrollView实现上下滑动功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解答下列问题:S—>S;T|T;T—>a 构造任意项目集规范族,构造LR(0)分析表,并分析a;a

对于这个文法,我们可以构造以下项目集规范族: I0: S -> .S S -> .T T -> .a I1: S -> S. [$ T -> T. [$ I2: S -> T. I3: S -> S.;S S -> S.;T T -> T.;a 其中,点(.)表示已经被扫描过的符号,;$表示输入串的结束符号。 根据项目集规范族,我们可以构造出LR(0)分析表: 状态 | a | $ ---- | - | - I0 | s3| I1 | |acc I2 | | 其中s3表示移进到状态3,acc表示接受。在分析字符串a;a时,我们可以按照以下步骤进行
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。