demo.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div>
  3. <nut-infiniteloading @loadmore="onInfinite" :is-show-mod="true" :has-more="isHasMore" :is-loading="isLoading" :threshold="200">
  4. <ul class="list">
  5. <li class="list-item" v-for="(item, index) of data" :key="item">我是测试数据{{ index + 1 }}</li>
  6. </ul>
  7. </nut-infiniteloading>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. data: new Array(30),
  15. page: 2,
  16. num: 30,
  17. isHasMore: true,
  18. isLoading: false,
  19. isErr: false,
  20. timer: null
  21. };
  22. },
  23. methods: {
  24. onInfinite() {
  25. this.isLoading = true;
  26. this.timer = setTimeout(() => {
  27. if (this.page <= 5) {
  28. this.data = new Array(this.num * this.page);
  29. this.page = this.page + 1;
  30. } else {
  31. this.isHasMore = false;
  32. }
  33. this.isLoading = false;
  34. }, 100);
  35. }
  36. },
  37. destroyed() {
  38. clearTimeout(this.timer);
  39. }
  40. };
  41. </script>
  42. <style lang="scss" scoped>
  43. .list {
  44. padding-top: 10px;
  45. .list-item {
  46. height: 50px;
  47. border: 1px solid mix($primary-color, #fff, 40%);
  48. margin-bottom: 10px;
  49. font-size: 12px;
  50. color: mix($primary-color, #fff, 80%);
  51. line-height: 50px;
  52. text-align: center;
  53. background-color: #fff;
  54. }
  55. }
  56. </style>