artlist.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view class="center">
  3. <view class="massage" v-for="(item, index) in list" :key="index"
  4. @click="nav('/pages/index/artDetail?id=' + item.id)">
  5. <view class="title">{{ item.title }}</view>
  6. <view class="time">{{ item.add_time }}</view>
  7. </view>
  8. <uni-load-more :status="loadingType"></uni-load-more>
  9. </view>
  10. </template>
  11. <script>
  12. import {
  13. article
  14. } from '@/api/user.js';
  15. export default {
  16. data() {
  17. return {
  18. list: [],
  19. type: '',
  20. page: 1,
  21. limit: 10,
  22. loadingType: 'more',
  23. };
  24. },
  25. onLoad(opt) {
  26. let obj = this;
  27. obj.type = opt.id
  28. obj.loadData()
  29. },
  30. onReachBottom() {
  31. this.loadData()
  32. },
  33. methods: {
  34. nav(url) {
  35. uni.navigateTo({
  36. url
  37. });
  38. },
  39. loadData() {
  40. let obj = this
  41. if (obj.loadingType === 'loading' || obj.loadingType === 'noMore') {
  42. //防止重复加载
  43. return;
  44. }
  45. obj.loadingType = 'loading'
  46. article({
  47. page: obj.page,
  48. limit: obj.limit
  49. }, this.type).then(({
  50. data
  51. }) => {
  52. obj.list = obj.list.concat(data);
  53. obj.page++
  54. if (data.length == obj.limit) {
  55. obj.loadingType = 'more';
  56. } else {
  57. obj.loadingType = 'noMore';
  58. }
  59. });
  60. }
  61. }
  62. };
  63. </script>
  64. <style lang="less">
  65. .center {
  66. background: #f3f3f3;
  67. }
  68. .massage {
  69. background: #ffffff;
  70. padding: 30rpx;
  71. border-bottom: 1px solid #e9e9e9;
  72. .title {
  73. font-size: 28rpx;
  74. font-family: PingFang SC;
  75. font-weight: 500;
  76. color: #333333;
  77. }
  78. .time {
  79. margin-top: 18rpx;
  80. font-size: 20rpx;
  81. font-family: PingFang SC;
  82. font-weight: 500;
  83. color: #999999;
  84. }
  85. }
  86. </style>