HarmonyOS应用开发-下拉刷新实现

鸿蒙时代
发布于 2022-4-22 10:29
浏览
1收藏

HarmonyOS应用开发-下拉刷新实现-鸿蒙开发者社区
一.创建项目
HarmonyOS应用开发-下拉刷新实现-鸿蒙开发者社区
二.示例代码
hml:

<div class="container">
    <refresh refreshing="{{fresh}}" onrefresh="refresh">
        <list class="list" scrolleffect="no">
            <list-item class="listitem" for="list">
                <div class="content">
                    <text class="text">{{$item}}</text>
                </div>
            </list-item>
        </list>
    </refresh>
</div>

css:

.container {
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
}

.list {
    width: 100%;
    height: 100%;
}

.listitem {
    width: 100%;
    height: 150px;
}

.content {
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.text {
    font-size: 35px;
    font-weight: bold;
}

js:

import prompt from '@system.prompt';
export default {
    data: {
        list:[],
        fresh:false
    },
    onInit() {
        this.list = [];
        for (var i = 0; i <= 2; i++) {
            var item = '列表元素' + i;
            this.list.push(item);
        }
    },
    refresh: function (e) {
        prompt.showToast({
            message: '刷新中...'
        })
        var that = this;
        that.fresh = e.refreshing;
        setTimeout(function () {
            that.fresh = false;
            var addItem = '更新元素';
            that.list.unshift(addItem);
            prompt.showToast({
                message: '刷新完成!'
            })
        }, 2000)
    }
}

三、效果展示
HarmonyOS应用开发-下拉刷新实现-鸿蒙开发者社区

分类
标签
HarmonyOS应用开发-下拉刷新实现.docx 71.52K 20次下载
收藏 1
回复
举报
回复
    相关推荐