Authored by 李奇

fixed:图片加载失败重试

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>
@@ -22,7 +22,7 @@ export function createChannel() { @@ -22,7 +22,7 @@ export function createChannel() {
22 return { 22 return {
23 state: { 23 state: {
24 home: {}, 24 home: {},
25 - slider: {}, 25 + slider: [],
26 about: {}, 26 about: {},
27 gender: 'men', 27 gender: 'men',
28 men: { 28 men: {