微信小程序:按顺序一张图片加载完后,再加载另一张

因为较小的图片会先加载出来,破坏了fileList的顺序,所以需要按顺序加载。代码使用了vant-weapp组件(Vant Weapp - 轻量、可靠的小程序 UI 组件库

wxml

复制代码
<view wx:for="{{fileList}}" wx:key="index" data-item='{{item}}' data-index="{{ index }}">
     <van-image use-loading-slot width="100%" height="120px" src="{{item.url}}" bindload="imageLoad" >
          <van-loading slot="loading" type="spinner" size="20" vertical />
     </van-image>
</view>

js

复制代码
Page({
  data: {
    // 当前加载的图片索引
    currentIndex: 0, 
    // 文件
    fileList: [{
      url:'XXX'
    },
    {
      url:'XXX'
    }],
  },
  onLoad(options) {
    this.getFiles();
  },
  getFiles() {
    this.setData({
      fileList: this.data.fileList[0]
    });
  },
  /**
   * 图片加载完成
   */
  imageLoad() {
    const nextIndex = this.data.currentIndex + 1;
    this.setData({
      currentIndex: nextIndex
    })
    // 如果还有下一张图片,继续加载
    if (nextIndex < this.data.fileList.length) {
      this.setData({
        fileList: this.data.fileList[nextIndex]
      });
    } else {
      console.log("所有图片加载完成!");
    }
  }
})
相关推荐
2501_915918414 小时前
HTTPS 代理失效,启用双向认证(mTLS)的 iOS 应用网络怎么抓包调试
android·网络·ios·小程序·https·uni-app·iphone
数字游民95275 小时前
半年时间大概上了70个web站和小程序,累计提示词超过20w
人工智能·ai·小程序·vibecoding·数字游民9527
说私域5 小时前
微商企业未来迭代的核心方向与多元探索——以链动2+1模式AI智能名片商城小程序为核心支撑
大数据·人工智能·小程序·流量运营·私域运营
27669582925 小时前
美团 小程序 mtgsig
python·小程序·node·js·mtgsig1.2·美团小程序·大众点评小程序
2501_915106326 小时前
混合应用(Hybrid)安全加固,不依赖源码对成品 IPA 混淆
android·安全·小程序·https·uni-app·iphone·webview
00后程序员张7 小时前
无需越狱,来对 iOS 设备进行调试、管理与分析
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张7 小时前
在 iOS 上架中如何批量方便快捷管理 Bundle ID
android·ios·小程序·https·uni-app·iphone·webview
韩立学长7 小时前
【开题答辩实录分享】以《智慧校园平台微信小程序》为例进行选题答辩实录分享
spring boot·微信小程序·小程序
CHU7290357 小时前
旧物回收小程序前端功能设计:以用户为核心构建环保便捷通道
小程序