vant-ui—list https://youzan.github.io/vant/#/zh-CN/list

1.main.js中引入依赖

  1. import { List } from 'vant';
  2. Vue.use(List);

2.使用组件

  1. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
  2. </van-list>
  3. export default {
  4. data() {
  5. return {
  6. list: [],
  7. loading: false,
  8. finished: false
  9. };
  10. },

3.发送请求

  1. export default {
  2. name:"Detail",
  3. data(){
  4. return{
  5. subjects:[],
  6. finished:false,
  7. count:10,
  8. loading:false
  9. }
  10. },
  11. mounted(){
  12. this.axios.get('/v2/movie/top250').then(res=>{ //初次渲染数据
  13. this.subjects=res.data.subjects;
  14. })
  15. },
  16. methods:{
  17. onLoad(){
  18. /* 异步更新数据 */ //上拉刷新
  19. var url=`https://douban-api.now.sh/v2/movie/top250?count=${this.count}&
  20. start=${this.subjects.length}`;
  21. this.axios.get(url).then(res=>{
  22. this.subjects=this.subjects.concat(res.data.subjects);
  23. // 加载状态结束
  24. this.loading=false;
  25. });
  26. /* 数据全部加载完成 */
  27. if(this.subjects.length>=250){
  28. this.finished=true;
  29. }
  30. }
  31. }
  32. }
  33. //
  34. <template>
  35. <div class="container">
  36. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
  37. <Movies :data="item" v-for="item of subjects" :key="item.id"></Movies>
  38. </van-list>
  39. </div>
  40. </template>