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

zio/stable
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
1 changed files with 7 additions and 2 deletions

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 })
},
})