66 lines
1.2 KiB
Vue
66 lines
1.2 KiB
Vue
<template>
|
|
<div ref="$container" class="image_wrapper">
|
|
<template v-if="props.src">
|
|
<div v-show="loading" class="placeholder"></div>
|
|
<img
|
|
v-show="!loading"
|
|
lazy-load
|
|
:src="props.src"
|
|
:style="{
|
|
cursor: props.src ? 'pointer' : 'default',
|
|
}"
|
|
@load="completed"
|
|
@click="tapEnlargePic"
|
|
/>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
<script lang="ts" setup>
|
|
const props = defineProps<{
|
|
src: string | null
|
|
}>()
|
|
const emit = defineEmits(['onTapEnlargeImg'])
|
|
const loading = ref(true)
|
|
|
|
const $container = ref()
|
|
function completed(event: any) {
|
|
loading.value = false
|
|
}
|
|
|
|
// 放大图片
|
|
function tapEnlargePic() {
|
|
if (props.src) {
|
|
emit('onTapEnlargeImg', props.src)
|
|
}
|
|
}
|
|
watch(
|
|
() => props.src,
|
|
() => {
|
|
loading.value = true
|
|
},
|
|
)
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.image_wrapper {
|
|
width: 100%;
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 0;
|
|
|
|
img {
|
|
border-radius: 1.67vh;
|
|
width: 100%;
|
|
max-height: 100%;
|
|
|
|
object-fit: contain;
|
|
}
|
|
.placeholder {
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba($color: #fff, $alpha: 0.6);
|
|
}
|
|
}
|
|
</style>
|