forked from Mirrors/elk
fix: don't include srcset
when showing blur placeholder (#347)
This commit is contained in:
parent
8537f9e0ae
commit
3b6b83ae7a
1 changed files with 7 additions and 2 deletions
|
@ -12,6 +12,10 @@ export default defineComponent({
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
srcset: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
setup(props, { attrs }) {
|
setup(props, { attrs }) {
|
||||||
const placeholderSrc = ref<string>()
|
const placeholderSrc = ref<string>()
|
||||||
|
@ -19,11 +23,12 @@ export default defineComponent({
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const img = document.createElement('img')
|
const img = document.createElement('img')
|
||||||
isLoaded.value = img.complete
|
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
isLoaded.value = true
|
isLoaded.value = true
|
||||||
}
|
}
|
||||||
img.src = props.src
|
img.src = props.src
|
||||||
|
if (props.srcset)
|
||||||
|
img.srcset = props.srcset
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isLoaded.value = true
|
isLoaded.value = true
|
||||||
}, 3_000)
|
}, 3_000)
|
||||||
|
@ -35,7 +40,7 @@ export default defineComponent({
|
||||||
})
|
})
|
||||||
|
|
||||||
return () => isLoaded.value || !placeholderSrc.value
|
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 })
|
: h('img', { ...attrs, src: placeholderSrc.value })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue