当前位置:   article > 正文

HarmonyOS应用开发-下拉刷新实现_鸿蒙listcontainer 支持下拉刷新

鸿蒙listcontainer 支持下拉刷新

  • 创建项目

 

 

 

  • 示例代码

hml:

  1. <div class="container">
  2. <refresh refreshing="{{fresh}}" onrefresh="refresh">
  3. <list class="list" scrolleffect="no">
  4. <list-item class="listitem" for="list">
  5. <div class="content">
  6. <text class="text">{{$item}}</text>
  7. </div>
  8. </list-item>
  9. </list>
  10. </refresh>
  11. </div>

 css:

  1. .container {
  2. flex-direction: column;
  3. align-items: center;
  4. width: 100%;
  5. height: 100%;
  6. }
  7. .list {
  8. width: 100%;
  9. height: 100%;
  10. }
  11. .listitem {
  12. width: 100%;
  13. height: 150px;
  14. }
  15. .content {
  16. width: 100%;
  17. height: 100%;
  18. flex-direction: column;
  19. align-items: center;
  20. justify-content: center;
  21. }
  22. .text {
  23. font-size: 35px;
  24. font-weight: bold;
  25. }

 js:

  1. import prompt from '@system.prompt';
  2. export default {
  3. data: {
  4. list:[],
  5. fresh:false
  6. },
  7. onInit() {
  8. this.list = [];
  9. for (var i = 0; i <= 2; i++) {
  10. var item = '列表元素' + i;
  11. this.list.push(item);
  12. }
  13. },
  14. refresh: function (e) {
  15. prompt.showToast({
  16. message: '刷新中...'
  17. })
  18. var that = this;
  19. that.fresh = e.refreshing;
  20. setTimeout(function () {
  21. that.fresh = false;
  22. var addItem = '更新元素';
  23. that.list.unshift(addItem);
  24. prompt.showToast({
  25. message: '刷新完成!'
  26. })
  27. }, 2000)
  28. }
  29. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/228865
推荐阅读
相关标签