当前位置:   article > 正文

vant实现上拉加载(vue2/vue3)_vant 上拉加载

vant 上拉加载

注意:vue2采用的2.13.2版本vant组件库   vue3采用的4.8.1版本vant组件库 

多的不说直接上代码

vue2实现上拉加载

  1. <template>
  2. <div class="branch">
  3. <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad" class="list">
  4. <van-cell v-for="item in cmpyBranchInfo" :key="item.id">
  5. <slot slot="title">
  6. <p class="title">{{ item.name }}</p>
  7. </slot>
  8. </van-cell>
  9. </van-list>
  10. </div>
  11. </template>
  12. <script>
  13. import {
  14. getCmpyBranchInfo
  15. } from '@/api/debtor'
  16. export default {
  17. data() {
  18. return {
  19. cmpyBranchInfo: [],
  20. loading: false,
  21. finished: false,
  22. total: 0,
  23. page: 1,
  24. size: 10
  25. }
  26. },
  27. mounted() {
  28. this.onLoad()
  29. },
  30. methods: {
  31. onLoad() {
  32. setTimeout(() => {
  33. this.init()
  34. }, 500);
  35. },
  36. init() {
  37. const params = {
  38. pageNum: this.page,
  39. pageSize: this.size
  40. }
  41. getCmpyBranchInfo(params).then((res) => {
  42. this.cmpyBranchInfo = [...this.cmpyBranchInfo, ...res.data.data.data]
  43. this.total = res.data.data.total
  44. this.loading = false
  45. this.page += 1
  46. if (this.cmpyBranchInfo.length >= res.data.data.total) {
  47. this.finished = true
  48. }
  49. this.loading = false
  50. })
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .branch {
  57. .list {
  58. .title {
  59. font-size: 14px;
  60. color: #1990FF;
  61. }
  62. }
  63. }
  64. </style>

vue3实现上拉加载

  1. <template>
  2. <div class="branch">
  3. <van-list
  4. :loading="loading"
  5. :finished="finished"
  6. @load="onLoad"
  7. finished-text="没有更多了"
  8. offset="10"
  9. class="list"
  10. :immediate-check="false"
  11. >
  12. <van-cell v-for="item in cmpyBranchInfo" :key="item.id">
  13. <template #title>
  14. <p class="title">{{ item.name }}</p>
  15. </template>
  16. </van-cell>
  17. </van-list>
  18. </div>
  19. </template>
  20. <script setup>
  21. import { ref,onMounted } from 'vue'
  22. import { getCmpyBranchInfo } from '@/api/debtor'
  23. const cmpyBranchInfo = ref([])
  24. const loading = ref(false)
  25. const finished = ref(false)
  26. const total = ref(0)
  27. const page = ref(0)
  28. const size = ref(20)
  29. onMounted(() => {
  30. onLoad()
  31. })
  32. const onLoad = () => {
  33. setTimeout(() => {
  34. page.value += 1
  35. init()
  36. }, 500);
  37. };
  38. const init = () => {
  39. const params = {
  40. pageNum: page.value,
  41. pageSize: size.value
  42. }
  43. getCmpyBranchInfo(params).then((res) => {
  44. cmpyBranchInfo.value = [...cmpyBranchInfo.value, ...res.data.data.data]
  45. total.value = res.data.data.total
  46. loading.value = false
  47. if (cmpyBranchInfo.value.length >= res.data.data.total) {
  48. finished.value = true
  49. }
  50. loading.value = false
  51. })
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .branch {
  56. .list {
  57. min-height: 100vh;
  58. height: auto;
  59. .title {
  60. font-size: 14px;
  61. }
  62. }
  63. }
  64. </style>

图片预览vue2/vue3配合vant组件库实现上拉加载

注:本人前端小白 ,如有不对的地方还请多多指教

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/730988
推荐阅读
相关标签
  

闽ICP备14008679号