|
@@ -1,13 +1,15 @@
|
|
|
<template>
|
|
<template>
|
|
|
<v-container fill-height fluid style="padding-left: 24px; padding-right: 24px">
|
|
<v-container fill-height fluid style="padding-left: 24px; padding-right: 24px">
|
|
|
- <v-row no-gutters>
|
|
|
|
|
- <v-col
|
|
|
|
|
- v-for="item in videoList"
|
|
|
|
|
- :key="item.id"
|
|
|
|
|
- >
|
|
|
|
|
- <VideoCared :video="item" />
|
|
|
|
|
- </v-col>
|
|
|
|
|
- </v-row>
|
|
|
|
|
|
|
+ <div v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
|
|
|
|
|
+ <v-row no-gutters>
|
|
|
|
|
+ <v-col
|
|
|
|
|
+ v-for="item in videoList"
|
|
|
|
|
+ :key="item.id"
|
|
|
|
|
+ >
|
|
|
|
|
+ <VideoCared :video="item" />
|
|
|
|
|
+ </v-col>
|
|
|
|
|
+ </v-row>
|
|
|
|
|
+ </div>
|
|
|
</v-container>
|
|
</v-container>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -22,26 +24,31 @@ export default {
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
- videoList: []
|
|
|
|
|
|
|
+ videoList: [],
|
|
|
|
|
+ busy: false,
|
|
|
|
|
+ page: 1
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- mounted() {
|
|
|
|
|
- // 监听页面是否滚动到底部
|
|
|
|
|
- window.addEventListener('scroll', this.lazyLoading, true)
|
|
|
|
|
- },
|
|
|
|
|
created() {
|
|
created() {
|
|
|
- this.getRecommendVideo()
|
|
|
|
|
- },
|
|
|
|
|
- destroyed() {
|
|
|
|
|
- // 页面离开后销毁,防止切换路由后上一个页面监听scroll滚动事件会在新页面报错问题
|
|
|
|
|
- window.removeEventListener('scroll', this.lazyLoading)
|
|
|
|
|
|
|
+ this.getRecommendVideo(this.page)
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
- getRecommendVideo() {
|
|
|
|
|
- videoRecommend()
|
|
|
|
|
|
|
+ loadMore: function() {
|
|
|
|
|
+ this.busy = true
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.getRecommendVideo(this.page)
|
|
|
|
|
+ }, 1000)
|
|
|
|
|
+ },
|
|
|
|
|
+ getRecommendVideo(page) {
|
|
|
|
|
+ videoRecommend(page)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
|
- this.videoList = res.data.list
|
|
|
|
|
|
|
+ // this.videoList = []
|
|
|
|
|
+ for (const item of res.data.list) {
|
|
|
|
|
+ this.videoList.push(item)
|
|
|
|
|
+ }
|
|
|
|
|
+ this.page += 1
|
|
|
|
|
+ this.busy = false
|
|
|
} else {
|
|
} else {
|
|
|
this.$notify({
|
|
this.$notify({
|
|
|
title: res.code,
|
|
title: res.code,
|
|
@@ -54,20 +61,6 @@ export default {
|
|
|
.catch(error => {
|
|
.catch(error => {
|
|
|
this.$message.error(error.message)
|
|
this.$message.error(error.message)
|
|
|
})
|
|
})
|
|
|
- },
|
|
|
|
|
- // 滚动操作
|
|
|
|
|
- lazyLoading() {
|
|
|
|
|
- // 滚动到底部,再加载的处理事件
|
|
|
|
|
- // 获取 可视区高度`、`滚动高度`、`页面高度`
|
|
|
|
|
- const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
|
|
|
|
|
- const clientHeight = document.documentElement.clientHeight
|
|
|
|
|
- const scrollHeight = document.documentElement.scrollHeight
|
|
|
|
|
- // 页面滚动到底部,逻辑代码
|
|
|
|
|
- if (scrollTop + clientHeight >= scrollHeight) {
|
|
|
|
|
- // TODO 页面滚动到底部时请求数据并渲染当前页面
|
|
|
|
|
- console.log('滚动到底部,触发')
|
|
|
|
|
- this.getRecommendVideo()
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|