feat(新组件): 背景图组件,用于使用img标签替代backImage的用法,以便于使用v-smart-img指令加载图片

This commit is contained in:
hzj 2026-01-05 17:44:11 +08:00
parent f1f7d04e28
commit 7c40b18777

View File

@ -0,0 +1,76 @@
<template>
<div class="bg-layer" :style="layerStyle">
<img
v-for="(imgSrc, index) in backgroundImages"
:key="index"
v-smart-img
:src="imgSrc"
:alt="`background-${index}`"
:class="['bg-image', imageClass]"
:style="imageStyle"
/>
</div>
</template>
<script setup>
import { computed } from 'vue'
const props = defineProps({
//
backgroundImages: {
type: Array,
required: true,
default: () => [],
},
//
layerStyle: {
type: Object,
default: () => ({
width: '100vw',
minHeight: '100vh',
position: 'absolute',
top: '0',
left: '0',
zIndex: 0,
pointerEvents: 'none',
}),
},
//
imageStyle: {
type: Object,
default: () => ({
width: '100vw',
objectFit: 'cover',
objectPosition: 'center top',
display: 'block',
}),
},
//
imageClass: {
type: String,
default: '',
},
})
</script>
<style scoped>
.bg-layer {
width: 100vw;
min-height: 100vh;
position: absolute;
top: 0;
left: 0;
z-index: 0;
pointer-events: none;
}
.bg-image {
width: 100vw;
object-fit: cover;
object-position: center top;
display: block;
}
</style>