img-lazy.vue
716 Bytes
<template>
<img v-if="lazy" v-lazy="currentSrc" alt="">
<img v-else :src="currentSrc" alt="">
</template>
<script>
import util from 'common/util';
export default {
name: 'img-lazy',
props: {
src: {
type: [Object, String]
},
lazy: {
type: Boolean,
default: true
}
},
computed: {
currentSrc() {
if (typeof this.src === 'string') {
return util.replaceHttp(this.src);
} else if (typeof this.src === 'object') {
let {src, width, height, mode} = this.src;
return util.getImgUrl(src, width, height, mode);
}
}
}
};
</script>