小程序開發二三事--圖片錯誤顯示默認圖


小程序的image組件不像普通html 的image,沒有onerror屬性,不過有個binderror回調方法。卻不像onerror="this.src='/static/img/fmdefault.png'"來的方便。

binderror 當錯誤發生時,發布到 AppService 的事件名,事件對象event.detail = {errMsg: 'something wrong'};

當圖片錯誤時,調用binderror方法,然后去改變image的src綁定的值。

<image class="userinfo-avatar" src="{{avatar}}" binderror="errorFunction"></image>

errorFunction: function(){
    this.setData({
      avatar: '/image/head.png'
    })    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM