从零用java实现 小红书 springboot vue uniapp (2)主页优化

前言

移动端演示 http://8.146.211.120:8081/#/

前面的文章我们基本完成了主页的布局
今天我们具体的去进行实现 并且分享我开发时遇到的问题

首先先看效果

java仿小红书主页

实现效果为

1.顶端全屏切换

2.上划加载更多

3.下拉当前页整体刷新

顶端全屏切换我们选择 gui-switch-navigation 结合 swiper swiper-item 进行实现

关键代码

bash 复制代码
			<gui-switch-navigation
					 :activeLineClass="['gui-xhs-red']"
					 :isCenter="true"
					 activeDirection="center"
					 textAlign="center"
					:items="tabs"
					:size="150"
					:currentIndex="currentIndex"
					@change="navchange"></gui-switch-navigation>

	<swiper
				:current="currentIndex"
				@change="swiperChange"
				:style="{
					height:mainHeight+'px',
					width:'750rpx'
				}">
					<!-- 轮播项目数量对应 上面的选项标签 -->
					<swiper-item >
						<!-- 使用滚动区域来实现主体内容区域 -->
						<scroll-view
						:style="{height:mainHeight+'px'}"
						:scroll-y="true"
						class="gui-bg-gray"
						>.................

下滑加载更多

当页面滑动到底端时 我们执行获取笔记的方法
每页的条数需要请求偶数 否则会出现 左侧多一个元素(详情参照上篇文章 瀑布流的实现) 每请求一次 当前页码加1 直至没有页数 组件提示没有更多

bash 复制代码
		getNotes1(isReload){
			console.log('我开始请求了')
			this.apiLoadingStatus1 = true;
			const that = this
			uni.app.get('/notes', {limit:6,page:this.page1}, '', (res => {
				if (res.code == 200) {
					console.log('当前页'+that.page1)
					console.log('总页数'+res.data.pages)
					if(that.page1<=res.data.pages){
						let notes = res.data.records;

						var lArr = that.noteList1[0];
						var rArr = that.noteList1[1];
						//填充数组[此处的 notes 数据应该来自与api接口数据]
						//数据格式见 "/data/data.js"
						for (var i = 0; i < notes.length; i++) {
							if (i % 2 == 0) {
								lArr.push(notes[i]);
							} else {
								rArr.push(notes[i]);
							}
						}
						that.noteList1 = [lArr, rArr];

						if(that.page1==res.data.pages){
							that.$refs.guipage1.nomore();
						}else{
							that.page1 = that.page1 + 1;
							that.$refs.guipage1.stoploadmore();
						}
						that.apiLoadingStatus1 = false;
						that.pageLoading1  = false;

						if(isReload){
							this.$refs.guipage1.endReload();
						}
					}
				}
			}))
		},

当做到下拉刷新时 命名我们的uniapp配置了

bash 复制代码
		{
		    "path" : "pages/switchPages/index",
		    "style" :
		    {
		        "navigationBarTitleText": "小红书",
		        "navigationStyle" : "custom",
				"enablePullDownRefresh":false,
				"disableScroll":true

			}
		}

依然会出现页面整体下拉的情况

如图

导致下拉刷新失效 后来查阅很多资料 发现需要在页面的最外层加上

bash 复制代码
@touchmove.stop.prevent="() => {}"

至此完美解决

当下拉时 我们只想刷新当前页 避免左右两个tab内容刷新

bash 复制代码
		reload  : function(){
			console.log(this.currentIndex)
			//根据当前index 确定清空的对象
			this['page'+(this.currentIndex+1)] = 1
			this['noteList'+(this.currentIndex+1)].splice(0,1,[]);
			this['noteList'+(this.currentIndex+1)].splice(1,1,[]);
			this['getNotes'+(this.currentIndex+1)](1);
		},

这样就可以选择当前下标数据进行请求了 至

至此主页内容基本开发完毕 下一篇我们讲解 笔记详情

代码地址
https://gitee.com/ddeatrr/springboot_vue_xhs

相关推荐
寒水馨6 分钟前
com.github.oshi : oshi-core 中文文档(中英对照·API·接口·操作手册·全版本)以6.4.0为例,含Maven依赖、jar包、源码
java·后端
0和1的舞者13 分钟前
SpringBoot日志框架全解析
java·学习·springboot·日志·打印·lombok
小毅&Nora27 分钟前
【Java线程安全实战】② ConcurrentHashMap 源码深度拆解:如何做到高性能并发?
java·安全·多线程
Knight_AL30 分钟前
阿里《Java 开发手册》下的对象构建与赋值规范实践
java·开发语言
步步为营DotNet44 分钟前
深入理解.NET 中的IHostedService:后台任务管理的基石
java·网络·.net
让我上个超影吧1 小时前
基于SpringBoot和Vue实现CAS单点登录
前端·vue.js·spring boot
独自破碎E1 小时前
Leetcode862和至少为K的最短子数组
java·开发语言
To Be Clean Coder1 小时前
【Spring源码】getBean源码实战(二)
java·后端·spring
washingtin2 小时前
Get “https://registry-1.docker.io/v2/“: context deadline exceeded
java·开发语言
一路往蓝-Anbo2 小时前
C语言从句柄到对象 (七) —— 给对象加把锁:RTOS 环境下的并发安全
java·c语言·开发语言·stm32·单片机·嵌入式硬件·算法