开始

开启下拉刷新的功能
image.png

  1. "enablePullDownRefresh": true,

image.png

  1. // 监听下拉刷新
  2. onPullDownRefresh() {
  3. },

把逻辑尽量写在methods里面
image.png

image.png

  1. // 获取数据
  2. getdata() {
  3. // 服务器获取数据
  4. // 赋值
  5. // 关闭下下拉刷新
  6. }

定义变量,把原有的数据赋值过来
image.png
随便改点内容
image.png
输入ustop
image.png

image.png

定时器来模拟。setTimeOut 改成es6语法。里面可以用this对象。
image.png
image.png

image.png

本节代码

  1. <template>
  2. <view class="body">
  3. <!-- 小纸条列表 -->
  4. <block v-for="(item,index) in list" :key="index">
  5. <paper-list :item="item" :index="index"></paper-list>
  6. </block>
  7. </view>
  8. </template>
  9. <script>
  10. import paperList from '@/components/paper/paper-list.vue';
  11. export default {
  12. components: {
  13. paperList
  14. },
  15. data() {
  16. return {
  17. list: [{
  18. userpic: "../../static/demo/userpic/12.jpg",
  19. username: "昵称",
  20. time: "10:21",
  21. data: "我是信息",
  22. noreadnum: 2
  23. },
  24. {
  25. userpic: "../../static/demo/userpic/12.jpg",
  26. username: "昵称",
  27. time: "10:21",
  28. data: "我是信息",
  29. noreadnum: 0
  30. },
  31. {
  32. userpic: "../../static/demo/userpic/12.jpg",
  33. username: "昵称",
  34. time: "10:21",
  35. data: "我是信息",
  36. noreadnum: 0
  37. },
  38. {
  39. userpic: "../../static/demo/userpic/12.jpg",
  40. username: "昵称",
  41. time: "10:21",
  42. data: "我是信息",
  43. noreadnum: 11
  44. }
  45. ]
  46. }
  47. },
  48. // 监听下拉刷新
  49. onPullDownRefresh() {
  50. this.getdata()
  51. },
  52. methods: {
  53. // 获取数据
  54. getdata() {
  55. setTimeout(() => {
  56. // 服务器获取数据
  57. let arr = [{
  58. userpic: "../../static/demo/userpic/12.jpg",
  59. username: "昵称1111",
  60. time: "10:21",
  61. data: "我是信息",
  62. noreadnum: 2
  63. },
  64. {
  65. userpic: "../../static/demo/userpic/12.jpg",
  66. username: "昵称222",
  67. time: "10:21",
  68. data: "我是信息",
  69. noreadnum: 0
  70. },
  71. {
  72. userpic: "../../static/demo/userpic/12.jpg",
  73. username: "昵称333",
  74. time: "10:21",
  75. data: "我是信息",
  76. noreadnum: 0
  77. },
  78. {
  79. userpic: "../../static/demo/userpic/12.jpg",
  80. username: "昵称444",
  81. time: "10:21",
  82. data: "我是信息",
  83. noreadnum: 11
  84. }
  85. ];
  86. // 赋值
  87. this.list = arr;
  88. // 关闭下拉刷新
  89. uni.stopPullDownRefresh();
  90. }, 2000);
  91. }
  92. }
  93. }
  94. </script>
  95. <style>
  96. .body {
  97. padding: 0 20upx;
  98. }
  99. </style>

结束