本文實(shí)例為大家分享了vue圖片加載與顯示默認(rèn)圖片的具體代碼,供大家參考,具體內(nèi)容如下
HTML:
<div class="content-show-img"> <div class="show-img"> <img class="default-image" :src="data.image" @load="successLoadImg" @error="errorLoadImg"> </div></div>
JS:
Vue.prototype.successLoadImg = function(event) { if (event.target.complete == true) { event.target.classList.remove("default-image");; var imgParentNode = event.target.parentNode; if(imgParentNode.classList.contains('show-img')==true){ imgParentNode.style.background = "#000"; } }};Vue.prototype.errorLoadImg = function(event) { event.target.classList.add("default-image");;};針對(duì)尺寸不統(tǒng)一的:先顯示默認(rèn)圖片,加載成功時(shí)移除默認(rèn)圖片,填充背景。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注