普遍方法:给gif链接添加时间戳 (不推荐:每次都重新下载资源十分浪费)
推荐方法:
普通JS:**
document.getElementById('gif-2').src='http://insightgraphicdesign.net/wp-content/uploads/2014/07/coke-responsive-logo_copy.gif'
vue:
<template>
<div class="box">
<img id="gif-1" :src="imgUrl" alt="animated gif" />
<p>
<a href="#" @click="go">Click to replay gif above</a>
</p>
</div>
</template>
<script>
export default {
data() {
return {
on: "go",
url:
"http://test-ml-res.beikewen.com/lectures/146/00002-1561099027045.gif",
imgUrl: null
};
},
methods: {
go() {
console.log("重播");
this.$nextTick(() => {
let oldUrl = this.imgUrl
this.imgUrl = null;
window.setTimeout(() => {
this.imgUrl = oldUrl;
});
});
}
},
created() {
this.imgUrl = this.url;
},
computed: {},
components: {}
};
</script>
<style lang='less' scoped>
.box {
text-align: center;
background: #e3e3e3;
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
> img {
width: 100%;
height: 400px;
}
}
</style>