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

因为较小的图片会先加载出来,破坏了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("所有图片加载完成!");
    }
  }
})
相关推荐
清风絮柳8 小时前
65.少儿英语微信小程序
vue.js·spring boot·微信小程序·小程序·毕业设计
tjsoft15 小时前
unigui开发微信小程序
微信小程序·小程序
m0_462803881 天前
“趣味运动会记分”功能教学指南
小程序
网络安全学习库1 天前
很喜欢Vue,但还是选择了React: AI时代的新考量
vue.js·人工智能·react.js·小程序·aigc·产品经理·ai编程
叱咤少帅(少帅)2 天前
Uniapp开发pc端,小程序和APK
小程序·uni-app
2501_915918412 天前
iOS性能测试工具 Instruments、Keymob的使用方法 不局限 FPS
android·ios·小程序·https·uni-app·iphone·webview
Chengbei112 天前
利用 LibreNMS snmpget 配置篡改实现 RCE 的完整攻击链
人工智能·web安全·网络安全·小程序·系统安全
苏灵凯2 天前
智能环境监测终端全栈设计:从单片机到微信小程序,手把手搞定!
单片机·嵌入式硬件·mcu·物联网·微信小程序·小程序·蓝牙模块
nhc0882 天前
贵阳纳海川科技有限公司・货运物流行业解决方案
科技·微信小程序·小程序·软件开发·小程序开发
admin and root2 天前
AWS S3 对象存储攻防&云安全之OSS存储桶漏洞
微信小程序·小程序·渗透测试·云计算·aws·src·攻防演练