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

因为较小的图片会先加载出来,破坏了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("所有图片加载完成!");
    }
  }
})
相关推荐
凡泰AI5 小时前
如何借助MCP打通企业APP内部服务:从统一调用到小程序承接
小程序·uni-app·app·mpaas·mcp·小程序容器
这是个栗子7 小时前
uni-app 微信小程序开发:常用函数总结(一)
微信小程序·小程序·uni-app·getcurrentpages
投票竞赛7 小时前
书法、绘画作品投票评选,图片投票小程序作品集排版
python·小程序
乐橙开放平台9 小时前
明厨亮灶笔记:乐橙轻应用 H5 + 小程序插件,一套 BFF 出两张播放凭证
人工智能·笔记·物联网·小程序·音视频·notepad++
AI品信智慧数智人11 小时前
从键盘打字到语音对话✨数字人交互重塑小程序用户体验新范式
小程序
爱勇宝1 天前
上线 20 多天后,我才发现小程序的图片上传一直不可用
微信小程序·智能小程序
2601_956743681 天前
上海小程序开发公司:本地优质厂商名录与源码私有化技术分析
小程序·开发经验·上海
科技小刘c1 天前
接单做小程序,我算了笔省下的时间账
小程序
2501_916008892 天前
苹果上架工具怎么选 不用 Mac 上架 App Store 的几种方案
android·macos·ios·小程序·uni-app·iphone·webview
万亿少女的梦1682 天前
基于微信小程序、Spring Boot与Vue3的智慧养老管理系统设计与实现
spring boot·redis·微信小程序·mybatis·vue3