Skip to content

Commit 1ecf51a

Browse files
perf(vue): use autoSizes to calculate sizes for preloading
1 parent 7bc2ce3 commit 1ecf51a

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

packages/vue/src/components/UnLazyImage.vue

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { onBeforeUnmount, ref, watchEffect } from 'vue'
3-
import { lazyLoad, loadImage, updateSizesAttribute } from 'unlazy'
3+
import { autoSizes as _autoSizes, lazyLoad, loadImage } from 'unlazy'
44
import type { ImgHTMLAttributes } from 'vue'
55
66
const props = defineProps<{
@@ -38,15 +38,8 @@ watchEffect(() => {
3838
return
3939
4040
if (props.preload) {
41-
updateSizesAttribute(target.value)
42-
43-
// Calculate the `sizes` attribute for sources inside a `<picture>` element
44-
if (target.value.parentElement?.tagName.toLowerCase() === 'picture') {
45-
[...target.value.parentElement.getElementsByTagName('source')].forEach(
46-
sourceTag => updateSizesAttribute(sourceTag),
47-
)
48-
}
49-
41+
if (props.autoSizes)
42+
_autoSizes(target.value)
5043
loadImage(target.value)
5144
return
5245
}

0 commit comments

Comments
 (0)