forked from vuejs/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeveloperImage.vue
57 lines (51 loc) · 1.09 KB
/
DeveloperImage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script setup lang="ts">
import { computed } from 'vue'
import partnerConfig from '../partnerConfig.js'
const { imageStorageUrl } = partnerConfig
const props = withDefaults(defineProps<{
src: string
alt: string
width: number
height: number
quality?: string
crop?: string
faceRecognition?: boolean
loading?: 'lazy' | 'eager'
className?: string
}>(), {
quality: 'q_auto:best',
crop: 'c_fit',
faceRecognition: false
})
const imageSrc = computed(() => {
const attributes = [
'f_auto',
'dpr_auto',
props.crop,
props.quality,
props.faceRecognition ? 'g_face' : '',
props.width ? `w_${props.width}` : '',
props.height ? `h_${props.height}` : '',
]
.filter((item) => item !== '')
.join(',')
return `${imageStorageUrl}/${attributes}/v1/${props.src.replace(/^\/+/, '')}`
})
</script>
<template>
<img
:src="imageSrc"
:alt="alt"
:width="width"
:height="height"
:loading="loading"
:class="['c-image', className || '']"
/>
</template>
<style scoped>
.c-image {
max-width: 100%;
height: auto;
vertical-align: top;
}
</style>