Skip to content

Commit b7742a7

Browse files
committed
feat(images): AttributeResponsiveImage component
1 parent 20f9964 commit b7742a7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<img
3+
:data-srcset="srcset"
4+
:data-aspectratio="aspectRatio"
5+
:data-parent-fit="parentFit"
6+
:alt="alt"
7+
class="lazyload"
8+
sizes="auto"
9+
>
10+
</template>
11+
12+
<script setup lang="ts">
13+
interface Props {
14+
src: string
15+
alt: string
16+
sizes?: string
17+
loading?: string
18+
aspectRatio?: string | boolean
19+
parentFit?: string | boolean
20+
}
21+
22+
const props = withDefaults(defineProps<Props>(), {
23+
sizes: '100vw',
24+
loading: 'lazy',
25+
aspectRatio: false,
26+
parentFit: false,
27+
})
28+
29+
const srcset = computed<string>(() => {
30+
const img = useImage()
31+
return img.getSizes(props.src, {
32+
sizes:
33+
'xs:100vw sm:100vw md:100vw lg:100vw xl:100vw xxl:100vw xxxl:100vw xxxxl:100vw xxxxxl:100vw',
34+
modifiers: {
35+
format: 'webp',
36+
quality: 60,
37+
},
38+
}).srcset
39+
})
40+
</script>

0 commit comments

Comments
 (0)