加载更多-分页

列表加载更多

Created: Sep 14, 2020 5:29 PM
功能: 加载更多

export default {
  name: "home-album",
  data() {
    return {
      params: {
        // 获取多少条数据
        limit: 30,
        // 关键字 “hot”
        order: 'hot',
        // 跳过多少条
        skip: 0
      },
      // 列表数组
      album: [],
      // 是否还有下一页
      hasMore: true
    }
  },
  methods: {
    /**
     * 获取列表数据
     */
    getList() {
      this.request({
        url: 'http://157.122.54.189:9088/image/v1/wallpaper/album',
        data: this.params
      }).then(result => {
        if (result.res.album.length === 0) {
          this.hasMore = false
          return
        }
        this.album = [...this.album, ...result.res.album]
      })
    },
    /**
     *加载更多
     */
    handleToLower() {
      if (this.hasMore) {
        this.params.skip += this.params.limit
        this.getList()
      } else {
        uni.showToast({
          title: '没有数据了',
          icon: 'none'
        })
      }
    }
  },
  mounted() {
    this.getList()
  }
}
</script>
posted @ 2020-10-02 23:19  彼_岸  阅读(181)  评论(0编辑  收藏  举报