普遍方法:给gif链接添加时间戳 (不推荐:每次都重新下载资源十分浪费)

    推荐方法:

    普通JS:**

    1. document.getElementById('gif-2').src='http://insightgraphicdesign.net/wp-content/uploads/2014/07/coke-responsive-logo_copy.gif'

    vue:

    1. <template>
    2. <div class="box">
    3. <img id="gif-1" :src="imgUrl" alt="animated gif" />
    4. <p>
    5. <a href="#" @click="go">Click to replay gif above</a>
    6. </p>
    7. </div>
    8. </template>
    9. <script>
    10. export default {
    11. data() {
    12. return {
    13. on: "go",
    14. url:
    15. "http://test-ml-res.beikewen.com/lectures/146/00002-1561099027045.gif",
    16. imgUrl: null
    17. };
    18. },
    19. methods: {
    20. go() {
    21. console.log("重播");
    22. this.$nextTick(() => {
    23. let oldUrl = this.imgUrl
    24. this.imgUrl = null;
    25. window.setTimeout(() => {
    26. this.imgUrl = oldUrl;
    27. });
    28. });
    29. }
    30. },
    31. created() {
    32. this.imgUrl = this.url;
    33. },
    34. computed: {},
    35. components: {}
    36. };
    37. </script>
    38. <style lang='less' scoped>
    39. .box {
    40. text-align: center;
    41. background: #e3e3e3;
    42. width: 100vw;
    43. height: 100vh;
    44. position: fixed;
    45. top: 0;
    46. left: 0;
    47. > img {
    48. width: 100%;
    49. height: 400px;
    50. }
    51. }
    52. </style>