homework.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view class="center">
  3. <view v-for="(item,index) in homeList" :key="index">
  4. </view>
  5. </view>
  6. </template>
  7. <script>
  8. import { gethomework } from '@/api/homework.js'
  9. export default {
  10. data(){
  11. return{
  12. homeList: [],
  13. limit: 10,
  14. page: 1,
  15. loadingType: 'more'
  16. }
  17. },
  18. onLoad() {
  19. this.loadData()
  20. },
  21. //下拉刷新
  22. onPullDownRefresh() {
  23. this.loadData('refresh');
  24. },
  25. //监听页面是否滚动到底部加载更多
  26. onReachBottom() {
  27. this.loadData();
  28. },
  29. methods: {
  30. async loadData(type = 'add', loading){
  31. let obj = this;
  32. if (type === 'add') {
  33. if (obj.loadingType === 'nomore') {
  34. return;
  35. }
  36. obj.loadingType = 'loading';
  37. } else {
  38. obj.loadingType = 'more';
  39. }
  40. if (type === 'refresh') {
  41. // 清空数组
  42. obj.courseList = [];
  43. obj.page = 1
  44. }
  45. //获取反馈列表
  46. gethomework({
  47. page: obj.page,
  48. limit: obj.limit
  49. }).then(e => {
  50. obj.homeList = obj.homeList.concat(e.data.data);
  51. console.log(obj.homeList)
  52. //判断是否还有下一页,有是more 没有是nomore
  53. if (obj.limit==e.data.length) {
  54. obj.page++
  55. obj.loadingType='more'
  56. } else{
  57. obj.loadingType='nomore'
  58. }
  59. if (type === 'refresh') {
  60. if (loading == 1) {
  61. uni.hideLoading();
  62. } else {
  63. uni.stopPullDownRefresh();
  64. }
  65. }
  66. })
  67. },
  68. }
  69. }
  70. </script>
  71. <style>
  72. </style>