liveh5-nuxt/app/components/x-image/index.vue
xingyy ff053a5a8c feat(image): 添加 webp 图片格式支持
- 在 x-image组件中添加 webp 格式支持
- 在 nuxt.config.js 中配置 ipx 图片处理- 添加 sharp 库以支持图片格式转换
- 修改 live store 中的 show1 变量初始值
- 调整 PaymentResults 组件中 price 的默认值
2025-01-23 20:02:20 +08:00

59 lines
993 B
Vue

<script setup>
import { showImagePreview } from 'vant';
const props = defineProps({
src: {
type: String,
default: ''
},
preview: {
type: Boolean,
default: true
},
// 用于控制图片尺寸
sizes: {
type: Array,
default: () => [320, 640, 768, 1024]
},
// 用于控制图片格式
format: {
type: String,
default: 'webp'
},
// 用于控制图片质量
quality: {
type: Number,
default: 80
}
})
const showImage = () => {
if (props.preview) {
showImagePreview([props.src]);
}
}
</script>
<template>
<nuxt-img
v-if="src"
loading="lazy"
v-bind="{ ...props, ...$attrs }"
style="object-fit: cover"
@click="showImage"
:src="src"
:modifiers="{ format: 'webp' }"
:sizes="sizes"
:format="format"
:quality="quality"
placeholder
/>
<van-empty v-else description="暂无" />
</template>
<style scoped>
:deep(img) {
width: 100%;
height: 100%;
}
</style>