解決方案:利用bindload判斷圖片加載完畢,修改狀態顯示圖片
wxml:
1 <view wx:for="{{flash}}"> 3 <image src="{{item.loadReady ? item.img : '默認圖'}}" bindload="imageLoadReady" data-index="{{index}}" data-key="flash"></image> 5 </view>
js:
1 //圖片加載 2 imageLoadReady(e){ 3 let th = this; 4 let images = th.data[e.currentTarget.dataset.key]; 5 images[e.currentTarget.dataset.index].loadReady = true; 6 th.setData({ 7 [e.currentTarget.dataset.key]:images 8 }) 9 }