Vue3封裝ElImageViewer預覽圖片的示例代碼
更新時間:2023年07月28日 11:07:05 作者:明知山_
本文主要介紹了Vue3封裝ElImageViewer預覽圖片的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
目錄結(jié)構(gòu)

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" //自定義函數(shù)組件無法使用全局組件,需要單獨引入
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
remove: {
type: Function, //傳入createApp中移除節(jié)點的方法
default: null,
},
// api文檔:https://element-plus.org/zh-CN/component/image.html#image-viewer-attributes
})
const show = ref(props.visible)
// 監(jiān)聽顯示的消失,需要移除dom
watch(() => show.value, (val) => {
!val && props.remove()
})
</script>index.js
import { createApp } from 'vue'
import index from './index.vue'
export default (options) => {
// 創(chuàng)建一個節(jié)點,并將組件掛載上去
const root = document.createElement('div')
document.body.appendChild(root)
const app = createApp(index, {
...options, visible: true, remove() {
app.unmount(root) //創(chuàng)建完后要進行銷毀
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"] })到此這篇關(guān)于Vue3封裝ElImageViewer預覽圖片的示例代碼的文章就介紹到這了,更多相關(guān)Vue3 ElImageViewer預覽圖片內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
- vue2.0 使用element-ui里的upload組件實現(xiàn)圖片預覽效果方法
- vue.js 圖片上傳并預覽及圖片更換功能的實現(xiàn)代碼
- vue+vant使用圖片預覽功能ImagePreview的問題解決
- Vue.js圖片預覽插件使用詳解
- vue2實現(xiàn)移動端上傳、預覽、壓縮圖片解決拍照旋轉(zhuǎn)問題
- vue element upload實現(xiàn)圖片本地預覽
- vue iview多張圖片大圖預覽、縮放翻轉(zhuǎn)
- 基于Vue2x的圖片預覽插件的示例代碼
- Vue使用v-viewer實現(xiàn)圖片預覽
- Vue+UpLoad實現(xiàn)上傳預覽和刪除圖片的實踐
相關(guān)文章
vue-cli4創(chuàng)建項目導入Element-UI踩過的坑及解決
這篇文章主要介紹了vue-cli4創(chuàng)建項目導入Element-UI踩過的坑及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-04-04
vue前端項目打包成Docker鏡像并運行的實現(xiàn)
這篇文章主要介紹了vue前端項目打包成Docker鏡像并運行的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
安裝vue3開發(fā)者工具但控制臺沒有顯示出vue選項的解決
這篇文章主要介紹了安裝vue3開發(fā)者工具但控制臺沒有顯示出vue選項的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10

