Vue3封裝ElImageViewer預(yù)覽圖片的示例代碼
目錄結(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ù)組件無(wú)法使用全局組件,需要單獨(dú)引入
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
remove: {
type: Function, //傳入createApp中移除節(jié)點(diǎn)的方法
default: null,
},
// api文檔:https://element-plus.org/zh-CN/component/image.html#image-viewer-attributes
})
const show = ref(props.visible)
// 監(jiān)聽(tīng)顯示的消失,需要移除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)建一個(gè)節(jié)點(diǎn),并將組件掛載上去
const root = document.createElement('div')
document.body.appendChild(root)
const app = createApp(index, {
...options, visible: true, remove() {
app.unmount(root) //創(chuàng)建完后要進(jìn)行銷毀
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預(yù)覽圖片的示例代碼的文章就介紹到這了,更多相關(guān)Vue3 ElImageViewer預(yù)覽圖片內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue2.0 使用element-ui里的upload組件實(shí)現(xiàn)圖片預(yù)覽效果方法
- vue.js 圖片上傳并預(yù)覽及圖片更換功能的實(shí)現(xiàn)代碼
- vue+vant使用圖片預(yù)覽功能ImagePreview的問(wèn)題解決
- Vue.js圖片預(yù)覽插件使用詳解
- vue2實(shí)現(xiàn)移動(dòng)端上傳、預(yù)覽、壓縮圖片解決拍照旋轉(zhuǎn)問(wèn)題
- vue element upload實(shí)現(xiàn)圖片本地預(yù)覽
- vue iview多張圖片大圖預(yù)覽、縮放翻轉(zhuǎn)
- 基于Vue2x的圖片預(yù)覽插件的示例代碼
- Vue使用v-viewer實(shí)現(xiàn)圖片預(yù)覽
- Vue+UpLoad實(shí)現(xiàn)上傳預(yù)覽和刪除圖片的實(shí)踐
相關(guān)文章
vue-cli4創(chuàng)建項(xiàng)目導(dǎo)入Element-UI踩過(guò)的坑及解決
這篇文章主要介紹了vue-cli4創(chuàng)建項(xiàng)目導(dǎo)入Element-UI踩過(guò)的坑及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04
vue前端項(xiàng)目打包成Docker鏡像并運(yùn)行的實(shí)現(xiàn)
這篇文章主要介紹了vue前端項(xiàng)目打包成Docker鏡像并運(yùn)行的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
安裝vue3開(kāi)發(fā)者工具但控制臺(tái)沒(méi)有顯示出vue選項(xiàng)的解決
這篇文章主要介紹了安裝vue3開(kāi)發(fā)者工具但控制臺(tái)沒(méi)有顯示出vue選項(xiàng)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫(huà)的步驟
最近在Vue項(xiàng)目中引入高德地圖,實(shí)現(xiàn)地圖展示與交互的方法和技術(shù),這里跟大家分享下,這篇文章主要給大家介紹了關(guān)于前端Vue3引入高德地圖并展示行駛軌跡動(dòng)畫(huà)的相關(guān)資料,需要的朋友可以參考下2024-09-09

