使用vant-ui组件库里的list组件

    1. <template>
    2. <div class="home">
    3. <van-list class="list" :immediate-check="isChecked" v-model="loading"
    4. :finished="finished" finished-text="没有更多了" @load="onLoad"> //自带加载属性
    5. <div class="container" v-for="item of movie" :key="item.id"> //循环的数据
    6. <router-link :to="'/detail/'+item.id">
    7. <img class="movie-pic" :src="item.images.small" />
    8. <p class="movie-title">{{item.title | format}}</p>
    9. </router-link>
    10. </div>
    11. </van-list>
    12. </div>
    13. </template>
    14. <script>
    15. export default {
    16. name: "home",
    17. data() {
    18. return {
    19. movie: [],
    20. id: "",
    21. loading: false,
    22. finished: false,
    23. start:0,
    24. isChecked:false
    25. };
    26. },
    27. mounted() {
    28. this.axios.get("/v2/movie/top250").then(res => {
    29. this.movie = res.data.subjects;
    30. this.id = res.data.subjects.id;
    31. });
    32. },
    33. methods: {
    34. onLoad() {
    35. // 异步更新数据
    36. setTimeout(() => {
    37. this.start +=20; // 一次更新多少条
    38. this.axios.get(`/v2/movie/top250?start=${this.start}`).then(res => {
    39. this.id = res.data.subjects.id;
    40. this.movie = [...this.movie,...res.data.subjects]; //请求的新数据拼接旧数据
    41. this.loading = false;
    42. });
    43. if (this.movie.length >240) { //当数组长度大于240时 ,就不再发送http请求
    44. this.finished = true;
    45. }
    46. }, 500);
    47. },
    48. }
    49. };
    50. </script>
    51. <style scoped>
    52. .container {
    53. width: 100px;
    54. height: 160px;
    55. margin-top: 20px;
    56. text-align: center;
    57. border: 1px solid gainsboro;
    58. box-shadow: 2px 4px 10px 2px rgb(129, 128, 128);
    59. }
    60. .movie-pic {
    61. width: 100px;
    62. height: 130px;
    63. }
    64. .movie-title {
    65. font-size: 15px;
    66. }
    67. .list{
    68. display: flex;
    69. justify-content: space-evenly;
    70. flex-wrap: wrap;
    71. }
    72. </style>