💭💭
✨: 日历的回显、搭建热门精选、下拉加载更多、搜索框搭建 | 旅途拾景
💟:东非不开森的主页
💜: 心若有所向往,何惧道阻且长💜💜
🌸: 如有错误或不足之处,希望可以指正,非常感谢😉


npm install dayjs
然后封装个工具
import dayjs from "dayjs";
export function formatMonthDay(date) {
return dayjs(date).format("MM月DD日")
}
export function getDiffDays(startDate, endDate) {
return dayjs(endDate).diff(startDate, "day")
}







css blablabla~


使用数据


调用网络请求


跳转页面


用$route来接收参数











效果图



效果图

然后就是调css了
呜呜呜 慢慢调吧
注:
当scrollTop + clientHeight >= scrollHeight的时候,就说明滑到底部了
此时发送网络请求,加载下一页数据








重点:
hooks的useScroll封装 用于方便使用
scrollTop ``scrollHeight的高度 定义isReachBottom控制网络请求的再次的触发+ 上滑的高度 >= 内容滑块总高度时 就说明已经滚动到底部了 就可再次请求数据onMounted中进行(因为setup内部东西加载是处于(beforeCreate和create声明周期之间) 进行完成之后记得取消事件import { onMounted, onUnmounted, ref } from "vue";
import { throttle } from "lodash";
export default function useScroll() {
const isReachBottom = ref(false)
const clientHeight = ref(0)
const scrollTop = ref(0)
const scrollHeight = ref(0)
// 获取各种高度(客户端 上滑高度 滑块内容总高度)
const scrollListenerHandler = throttle(() => {
clientHeight.value = document.documentElement.clientHeight
scrollTop.value = document.documentElement.scrollTop
scrollHeight.value = document.documentElement.scrollHeight
if (clientHeight.value + scrollTop.value >= scrollHeight.value) {
// 滚动到底部触发
// console.log('gundao dibu l')
isReachBottom.value = true
}
}, 150)
// 监听事件
onMounted(() => {
window.addEventListener('scroll', scrollListenerHandler)
})
//移除事件
onUnmounted(() => {
window.removeEventListener('scroll', scrollListenerHandler)
})
return { isReachBottom, clientHeight, scrollTop, scrollHeight }
}











