微信小程序圖片加載失敗時默認圖片處理

微信小程序中img標籤不支持onerror事件,但是我希望當img加載圖片失敗的時候有一個加載默認圖片的效果。

解決:

可以使用@error

  <view class="car" v-for="(item, i) in dataList" :key="i" >
      <image class="car-image" :src="item.imageUrl" @error="imageError($event, i, dataList, 'imageUrl')" />
<view

 imageError(e, index, arr, key = 'imageUrl') {
      arr[index][key] = 'https://你的默認圖url'
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章