page-learn.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="scroll">
  3. <div>
  4. <van-tabs :active="active" @click="tabChange">
  5. <van-tab
  6. v-for="(item, index) in learnModuleList"
  7. :key="index"
  8. :title="item.title"
  9. >
  10. <van-list
  11. v-model="loading"
  12. :finished="finished"
  13. finished-text="没有更多了"
  14. @load="onLoad"
  15. >
  16. <van-cell v-for="item in item.content" :key="item" :title="item" />
  17. </van-list>
  18. </van-tab>
  19. </van-tabs>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. name: "page-learn",
  26. components: {},
  27. data() {
  28. return {
  29. active: 0,
  30. learnModuleList: [
  31. { title: "推荐", code: "recommend", content: [] },
  32. { title: "实践", code: "practice", content: [] },
  33. { title: "百科", code: "encyclopedia", content: [] },
  34. { title: "推荐", code: "recommend", content: [] },
  35. { title: "实践", code: "practice", content: [] },
  36. { title: "百科", code: "encyclopedia", content: [] },
  37. { title: "推荐", code: "recommend", content: [] },
  38. { title: "实践", code: "practice", content: [] },
  39. { title: "百科", code: "encyclopedia", content: [] }
  40. ],
  41. choosedTabIndex: 0,
  42. choosedTabTitle: "推荐",
  43. loading: true,
  44. finished: false
  45. };
  46. },
  47. computed: {},
  48. created() {
  49. this.onLoad();
  50. },
  51. mounted() {},
  52. methods: {
  53. tabChange(index, title) {
  54. this.choosedTabIndex = index;
  55. this.choosedTabTitle = title;
  56. console.log("---index--" + index + "--title--" + title);
  57. this.initLoadStatus();
  58. this.onLoad();
  59. },
  60. initLoadStatus() {
  61. this.loading = true;
  62. this.finished = false;
  63. },
  64. onLoad() {
  65. // 异步更新数据
  66. setTimeout(() => {
  67. for (let i = 0; i < 10; i++) {
  68. this.learnModuleList[this.choosedTabIndex].content.push(
  69. this.choosedTabTitle + i
  70. );
  71. }
  72. // 加载状态结束
  73. this.loading = false;
  74. // 数据全部加载完成
  75. if (this.learnModuleList[this.choosedTabIndex].content.length >= 40) {
  76. this.finished = true;
  77. }
  78. }, 1000);
  79. }
  80. }
  81. };
  82. </script>
  83. <style lang="scss" scoped>
  84. @import "~@/styles/mixin";
  85. .contentBody {
  86. background-color: #fff;
  87. }
  88. </style>