首页 小组 问答 话题 好文 素材 用户 唠叨 我的社区

[分享]如何在鸿蒙系统中实现网络图片加载时显示进度条?

风轻yLv.1种子选手
2024-09-19 18:55:08
0
54


// 设置UI,添加进度条组件
Progress({ value: 0, total: 100, type: ProgressType.Linear }).width(200).height(50)

// 异步下载图片,更新进度条
function downloadImage(url, progressCallback) {
    fetch(url)
        .then(response => response.blob())
        .then(blob => {
            progressCallback(100); // 假设下载完成
            displayImage(blob); // 显示图片
        })
        .onProgress(e => {
            progressCallback(Math.round((e.loaded / e.total) * 100)); // 更新进度条
        });
}

// 显示图片
function displayImage(blob) {
    const imageSrc = URL.createObjectURL(blob);
    // 更新图片组件的src属性来显示图片
}
风轻y
风轻y

33 天前

签名 :   54       0
评论
站长交流