vue 圖片404問題


img標簽,當src的url404時

1、使用默認圖片代替

<img style="margin-left: 40px;width: 130px;height: 130px;" :src="url" @error="nofindImg()"/>

    nofindImg(){

      let img = event.srcElement;

      img.src = "../../../static/404.png";

      img.onerror = null; //防止一直跳動

    },

2、not found,直接刪除標簽

<img style="margin-left: 40px;width: 130px;height: 130px;" :src="url"  :οnerrοr="default"/>

data中定義默認圖地址

  data() {

    return {

       default: 'this.remove()'

    };



作者:踩着陽光
鏈接:https://www.jianshu.com/p/c83ed05c57a1
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。


免責聲明!

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



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