fix: don't include srcset when showing blur placeholder (#347)

This commit is contained in:
Guillaume Chau 2022-12-06 16:10:53 +01:00 committed by GitHub
parent 8537f9e0ae
commit 3b6b83ae7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,10 @@ export default defineComponent({
type: String,
required: true,
},
srcset: {
type: String,
required: false,
},
},
setup(props, { attrs }) {
const placeholderSrc = ref<string>()
@ -19,11 +23,12 @@ export default defineComponent({
onMounted(() => {
const img = document.createElement('img')
isLoaded.value = img.complete
img.onload = () => {
isLoaded.value = true
}
img.src = props.src
if (props.srcset)
img.srcset = props.srcset
setTimeout(() => {
isLoaded.value = true
}, 3_000)
@ -35,7 +40,7 @@ export default defineComponent({
})
return () => isLoaded.value || !placeholderSrc.value
? h('img', { ...attrs, src: props.src })
? h('img', { ...attrs, src: props.src, srcset: props.srcset })
: h('img', { ...attrs, src: placeholderSrc.value })
},
})