木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

1 month ago
1 month ago
1 month ago
1 month ago
  1. // 简化版列表的混入
  2. export default {
  3. data() {
  4. return {
  5. list: [],
  6. params: {
  7. pageNo : 1,
  8. pageSize : 10,
  9. },
  10. mixinListApi: '',
  11. isLoading: false
  12. }
  13. },
  14. methods: {
  15. initData() {
  16. this.list = []
  17. this.params.pageNo = 1
  18. this.params.pageSize = 10
  19. },
  20. async getList() {
  21. this.isLoading = true
  22. if (!this.$api[this.mixinListApi]) {
  23. console.log('mixinApi不存在', this.mixinListApi);
  24. return
  25. }
  26. const res = await this.$api[this.mixinListApi]({
  27. ...this.params
  28. })
  29. if (res.code === 200 && res.result.record.length) {
  30. this.list = [...this.list, ...res.result.record]
  31. this.params.pageNo++
  32. }else {
  33. uni.showToast({
  34. title: '暂无数据',
  35. icon: 'none'
  36. })
  37. }
  38. // 如果有在加载中
  39. if (this.isLoading) {
  40. this.isLoading = false
  41. }
  42. // 有过有在下拉加载
  43. uni.stopPullDownRefresh()
  44. },
  45. },
  46. async onShow() {
  47. await this.getList()
  48. },
  49. onHide() {
  50. this.initData()
  51. },
  52. async onPullDownRefresh() {
  53. this.initData()
  54. await this.getList()
  55. },
  56. async onReachBottom() {
  57. await this.getList()
  58. }
  59. }