Index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div>
  3. <!--电影列表,与推荐列表-->
  4. <el-row v-if="videoList.length !== 0" id="movie-list"
  5. v-infinite-scroll="load"
  6. infinite-scroll-disabled="loading"
  7. infinite-scroll-distance="10">
  8. <!--电影列表-->
  9. <el-col :md="24">
  10. <el-col v-for="(video, index) in videoList" :key="index" :md="6" :sm="12" :xs="12">
  11. <video-card :video="video" />
  12. </el-col>
  13. </el-col>
  14. <!--热播列表-->
  15. <!-- <el-col :md="6">
  16. <hot-list />
  17. </el-col>-->
  18. </el-row>
  19. <el-row v-else class="not-result">
  20. <el-col :span="12" :offset="6">
  21. <img src="@/assets/img/icon/not-collection.png">
  22. <div>暂无推荐数据</div>
  23. </el-col>
  24. </el-row>
  25. </div>
  26. </template>
  27. <script>
  28. import VideoCard from '@/components/card/VideoCard'
  29. import Recommend from '@/components/recommend/Recommend'
  30. import { videoRecommend } from '@/api/video'
  31. export default {
  32. name: 'Index',
  33. components: { VideoCard, Recommend },
  34. data() {
  35. return {
  36. // 屏幕宽度, 为了控制分页条的大小
  37. screenWidth: document.body.clientWidth,
  38. currentPage: 1,
  39. videoList: [],
  40. loading: false
  41. }
  42. },
  43. created() {
  44. this.videoRecommendWrapper(this.currentPage)
  45. },
  46. mounted() {
  47. // 当窗口宽度改变时获取屏幕宽度
  48. window.onresize = () => {
  49. return () => {
  50. window.screenWidth = document.body.clientWidth
  51. this.screenWidth = window.screenWidth
  52. }
  53. }
  54. },
  55. methods: {
  56. videoRecommendWrapper(pageNumber) {
  57. videoRecommend(pageNumber).then(res => {
  58. if (res.code === 0) {
  59. const resList = res.data.list
  60. if (resList.length === 0) {
  61. this.loading = false
  62. return
  63. }
  64. for (const item of res.data.list) {
  65. this.videoList.push(item)
  66. }
  67. this.currentPage +=1
  68. this.loading = false
  69. } else {
  70. this.$notify(
  71. {
  72. title: '提示',
  73. message: '获取数据失败, 请重新刷新页面',
  74. type: 'warning',
  75. duration: 3000
  76. }
  77. )
  78. }
  79. })
  80. },
  81. load() {
  82. if (this.currentPage > 20) {
  83. return
  84. }
  85. this.loading = true
  86. setTimeout(() => {
  87. this.videoRecommendWrapper(this.currentPage)
  88. }, 1000)
  89. }
  90. }
  91. }
  92. </script>
  93. <style scoped>
  94. #movie-list {
  95. padding-top: 15px;
  96. padding-left: 6%;
  97. padding-right: 6%;
  98. }
  99. /*处于手机屏幕时*/
  100. @media screen and (max-width: 768px){
  101. #movie-list {
  102. padding-top: 8px;
  103. padding-left: 0.5%;
  104. padding-right: 0.5%;
  105. }
  106. }
  107. </style>