【Vue】image 显示预设图 | @load

@load 用在图片标籤时

image src 有值的时候,才会开始加载onload 事件是在 src 的资源加载完毕的时候,才会触发
<img src="showImg.png" @load="isLoad">methods:{    isLoad(){        console.log('资料加载完毕')    }}

实际製作图片的预设图

template

<div class="loading-image">    <img @load="successLoadImg" v-bind:src="spot.Picture.PictureUrl1" alt="载入图片"></div>

style

.loading-image{    height: 100%;    position: relative;    background-color: #FFF;    background-image: url(../src/assets/loading.png);    background-repeat: no-repeat;    background-size: 100%;    &.hide{        display: none;    }}

js
利用 prototype 设定全局函式,可以重複使用。

Vue.prototype.successLoadImg = function (event){    event.target.parentElement.classList.add('hide');    document.querySelectorAll(".loading-image.hide").forEach(e => e.remove())};

参考来源:
https://blog.csdn.net/muzidigbig/article/details/115167044
https://www.itread01.com/article/1489633818.html


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章