Skip to content

Instantly share code, notes, and snippets.

@PKTseng
Last active August 4, 2020 01:38
Show Gist options
  • Save PKTseng/472e4cbc62ff4f6f35d3438ff5b44714 to your computer and use it in GitHub Desktop.
Save PKTseng/472e4cbc62ff4f6f35d3438ff5b44714 to your computer and use it in GitHub Desktop.
偵聽圖片 onload 事件
<div id="app">
<h2 v-if="loading">Loading</h2>
<h2 v-else>complete</h2>
<img
:class="imgClass"
@load="loading = false"
src="https://picsum.photos/500/300" alt="">
</div>
new Vue({
el:"#app",
data:{
loading: true,
},
computed:{
imgClass(){
if(this.loading){
return 'img hide';
}else{
return 'img';
}
},
},
})
.img.hide{
opacity: 0;
}
.img{
transition: opacity 1.5s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment