Vue3封装ElImageViewer预览图片的示例代码
更新时间:2023年07月28日 11:07:05 作者:明知山_
本文主要介绍了Vue3封装ElImageViewer预览图片的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
目录结构

index.vue
<template>
<el-image-viewer v-if="show" v-bind="$attrs" hide-on-click-modal @close="show = false" />
</template>
<script setup>
import { ref, watch } from "vue"
import { ElImageViewer } from "element-plus" //自定义函数组件无法使用全局组件,需要单独引入
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
remove: {
type: Function, //传入createApp中移除节点的方法
default: null,
},
// api文档:https://element-plus.org/zh-CN/component/image.html#image-viewer-attributes
})
const show = ref(props.visible)
// 监听显示的消失,需要移除dom
watch(() => show.value, (val) => {
!val && props.remove()
})
</script>index.js
import { createApp } from 'vue'
import index from './index.vue'
export default (options) => {
// 创建一个节点,并将组件挂载上去
const root = document.createElement('div')
document.body.appendChild(root)
const app = createApp(index, {
...options, visible: true, remove() {
app.unmount(root) //创建完后要进行销毁
document.body.removeChild(root)
}
})
return app.mount(root)
}使用方法在js||vue文件中
import previewImage from "@/fcComponents/previewImage"
previewImage({ urlList: ["https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg"] })到此这篇关于Vue3封装ElImageViewer预览图片的示例代码的文章就介绍到这了,更多相关Vue3 ElImageViewer预览图片内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
对Vue- 动态元素属性及v-bind和v-model的区别详解
今天小编就为大家分享一篇对Vue- 动态元素属性及v-bind和v-model的区别详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-08-08
详解Vue3.0中ElementPlus<input输入框自动获取焦点>
这篇文章主要给大家介绍了关于Vue3.0中ElementPlus<input输入框自动获取焦点>的相关资料,文中通过实例代码介绍的非常详细,对大家学习或者使用vue3.0具有一定的参考学习价值,需要的朋友可以参考下2023-04-04
vuex+axios+element-ui实现页面请求loading操作示例
这篇文章主要介绍了vuex+axios+element-ui实现页面请求loading操作,结合实例形式分析了vuex+axios+element-ui实现页面请求过程中loading遮罩层相关操作技巧与使用注意事项,需要的朋友可以参考下2020-02-02
unplugin-auto-import的配置以及eslint报错解决详解
unplugin-auto-import 解决了vue3-hook、vue-router、useVue等多个插件的自动导入,也支持自定义插件的自动导入,是一个功能强大的typescript支持工具,这篇文章主要给大家介绍了关于unplugin-auto-import的配置以及eslint报错解决的相关资料,需要的朋友可以参考下2022-08-08


最新评论