Showing
2 changed files
with
20 additions
and
2 deletions
1 | <template> | 1 | <template> |
2 | <img v-if="lazy" v-lazy="currentSrc" alt="" :width="width" :height="height"> | 2 | <img v-if="lazy" v-lazy="currentSrc" alt="" :width="width" :height="height"> |
3 | - <img v-else :src="currentSrc" alt="" :width="width" :height="height"> | 3 | + <img v-else ref="image" :src="currentSrc" alt="" :width="width" :height="height"> |
4 | </template> | 4 | </template> |
5 | 5 | ||
6 | <script> | 6 | <script> |
@@ -27,6 +27,24 @@ export default { | @@ -27,6 +27,24 @@ export default { | ||
27 | } | 27 | } |
28 | return this.src; | 28 | return this.src; |
29 | } | 29 | } |
30 | + }, | ||
31 | + mounted() { | ||
32 | + let timer; | ||
33 | + let img = new Image(); | ||
34 | + let maxRetry = 30 * 1000; | ||
35 | + let start = Date.now(); | ||
36 | + | ||
37 | + timer = setInterval(() => { | ||
38 | + img.src = this.$refs.image.src; | ||
39 | + | ||
40 | + if (!img.src) { | ||
41 | + clearInterval(timer); | ||
42 | + } | ||
43 | + | ||
44 | + if (img.complete || Date.now() - start > maxRetry) { | ||
45 | + clearInterval(timer); | ||
46 | + } | ||
47 | + }, 3000); | ||
30 | } | 48 | } |
31 | }; | 49 | }; |
32 | </script> | 50 | </script> |
-
Please register or login to post a comment