小程序端工程代码
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.

108 lines
2.9 KiB

  1. <template>
  2. <view class="newsList" ref="container">
  3. <view class="list" v-for="(item, articleListIndex) in articleList" :key="articleListIndex">
  4. <view @click="goNewsDetail(item)" class="item acea-row row-between-wrapper">
  5. <view class="text acea-row row-column-between">
  6. <view class="name line2">{{ item.title }}</view>
  7. <view>{{ item.addTime }}</view>
  8. </view>
  9. <view class="pictrue">
  10. <image :src="item.imageInput" />
  11. </view>
  12. </view>
  13. </view>
  14. <!--暂无新闻-->
  15. <view class="noCommodity" v-if="articleList.length === 0 && page > 1">
  16. <view class="noPictrue">
  17. <image :src="`${$VUE_APP_RESOURCES_URL}/images/noNews.png`" class="image" />
  18. </view>
  19. </view>
  20. <!--</Tab>-->
  21. <!--</Tabs>-->
  22. </view>
  23. </template>
  24. <script>
  25. import { getArticleList } from "@/api/public";
  26. export default {
  27. name: "NewsList",
  28. components: {},
  29. props: {},
  30. data: function() {
  31. return {
  32. page: 1,
  33. limit: 20,
  34. loadTitle: "",
  35. loading: false,
  36. loadend: false,
  37. imgUrls: [],
  38. navLsit: [],
  39. articleList: [],
  40. active: 0,
  41. cid: 0,
  42. swiperNew: {
  43. pagination: {
  44. el: ".swiper-pagination",
  45. clickable: true
  46. },
  47. autoplay: {
  48. disableOnInteraction: false,
  49. delay: 2000
  50. },
  51. loop: true,
  52. speed: 1000,
  53. observer: true,
  54. observeParents: true
  55. }
  56. };
  57. },
  58. mounted: function() {
  59. // this.articleBanner();
  60. //this.articleCategory();
  61. this.getArticleLists();
  62. // this.$scroll(this.$refs.container, () => {
  63. // !this.loading && this.getArticleLists();
  64. // });
  65. },
  66. onReachBottom() {
  67. !this.loading && this.getArticleLists();
  68. },
  69. methods: {
  70. goNewsDetail(item) {
  71. this.$yrouter.push({
  72. path: "/pages/shop/news/NewsDetail/index",
  73. query: { id: item.id }
  74. });
  75. },
  76. getArticleLists: function() {
  77. let that = this;
  78. if (that.loading) return; //阻止下次请求(false可以进行请求);
  79. if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
  80. that.loading = true;
  81. let q = {
  82. page: that.page,
  83. limit: that.limit
  84. };
  85. getArticleList(q).then(res => {
  86. that.loading = false;
  87. //apply();js将一个数组插入另一个数组;
  88. that.articleList.push.apply(that.articleList, res.data);
  89. that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
  90. that.page = that.page + 1;
  91. });
  92. },
  93. onClick: function(name) {
  94. if (name === 0) this.articleHotList();
  95. else {
  96. this.cid = this.navLsit[name].id;
  97. this.articleList = [];
  98. this.page = 1;
  99. this.loadend = false;
  100. this.loading = false;
  101. this.getArticleLists(name);
  102. }
  103. }
  104. }
  105. };
  106. </script>