Authored by 李奇

fixed:图片加载失败重试

<template>
<img v-if="lazy" v-lazy="currentSrc" alt="" :width="width" :height="height">
<img v-else :src="currentSrc" alt="" :width="width" :height="height">
<img v-else ref="image" :src="currentSrc" alt="" :width="width" :height="height">
</template>
<script>
... ... @@ -27,6 +27,24 @@ export default {
}
return this.src;
}
},
mounted() {
let timer;
let img = new Image();
let maxRetry = 30 * 1000;
let start = Date.now();
timer = setInterval(() => {
img.src = this.$refs.image.src;
if (!img.src) {
clearInterval(timer);
}
if (img.complete || Date.now() - start > maxRetry) {
clearInterval(timer);
}
}, 3000);
}
};
</script>
... ...
... ... @@ -22,7 +22,7 @@ export function createChannel() {
return {
state: {
home: {},
slider: {},
slider: [],
about: {},
gender: 'men',
men: {
... ...