Element Plus 自定义图片预览组件
155 字
1 分钟
Element Plus 自定义图片预览组件
创建一个图片预览组件
<script setup lang="ts">import { ref, watchEffect } from "vue";
const props = defineProps<{ imageList?: string[];}>();
const visible = ref(false);const list = ref<string[]>([]);const currentIndex = ref<number>(0);
watchEffect(() => { const { imageList } = props; if (!imageList?.length) return; list.value = [...imageList];});
function open(data: { previewIndex: number }) { const { previewIndex } = data; currentIndex.value = previewIndex; visible.value = true;}
const emit = defineEmits<{ (e: "close"): void;}>();
function close() { visible.value = false; emit("close");}
// 切换图片时触发function onSwitch(index: number) { currentIndex.value = index;}
defineExpose({ open, close,});</script>
<template> <div id="image-preview" v-if="visible"> <el-image-viewer :url-list="list" @close="close" @switch="onSwitch" :initial-index="currentIndex" show-progress > </el-image-viewer> </div></template>
<style scoped lang="scss">#image-preview { position: relative;
:deep(.el-image-viewer__progress) { position: absolute; top: 0; height: 40px; width: 100%; background: rgba(0, 0, 0, 0.1); border-radius: 0; font-weight: 400; }}</style>支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!
Element Plus 自定义图片预览组件
https://blog.ddlyt.top/posts/2025/0516/相关文章智能推荐
1
Vue3 封装命令式组件
学习笔记封装命令式组件的几种方式
2
Python 笔记:工程实践与常见陷阱
学习笔记uv 包管理、导入系统、类型注解、面向对象、异常与常用标准库,写给前端开发者的工程速查。
3
Python 笔记:给前端开发者的语法对照
学习笔记用 JavaScript 的思维快速理解 Python 中真正不同的语法。
4
如何优化vue项目的白屏时间
技术分享希望可以帮到你
5
什么?都5202年了,你还不会Grid布局?
技术分享一些Grid布局的基本语法
随机文章随机推荐






























































































































































