Vue3封裝ElImageViewer預(yù)覽圖片的示例代碼
更新時間:2023年07月28日 11:07:05 作者:明知山_
本文主要介紹了Vue3封裝ElImageViewer預(yù)覽圖片的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
目錄結(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預(yù)覽圖片的示例代碼的文章就介紹到這了,更多相關(guān)Vue3 ElImageViewer預(yù)覽圖片內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
- vue2.0 使用element-ui里的upload組件實現(xiàn)圖片預(yù)覽效果方法
- vue.js 圖片上傳并預(yù)覽及圖片更換功能的實現(xiàn)代碼
- vue+vant使用圖片預(yù)覽功能ImagePreview的問題解決
- Vue.js圖片預(yù)覽插件使用詳解
- vue2實現(xiàn)移動端上傳、預(yù)覽、壓縮圖片解決拍照旋轉(zhuǎn)問題
- vue element upload實現(xiàn)圖片本地預(yù)覽
- vue iview多張圖片大圖預(yù)覽、縮放翻轉(zhuǎn)
- 基于Vue2x的圖片預(yù)覽插件的示例代碼
- Vue使用v-viewer實現(xiàn)圖片預(yù)覽
- Vue+UpLoad實現(xiàn)上傳預(yù)覽和刪除圖片的實踐
相關(guān)文章
對Vue- 動態(tài)元素屬性及v-bind和v-model的區(qū)別詳解
今天小編就為大家分享一篇對Vue- 動態(tài)元素屬性及v-bind和v-model的區(qū)別詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08詳解Vue3.0中ElementPlus<input輸入框自動獲取焦點>
這篇文章主要給大家介紹了關(guān)于Vue3.0中ElementPlus<input輸入框自動獲取焦點>的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue3.0具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2023-04-04vuex+axios+element-ui實現(xiàn)頁面請求loading操作示例
這篇文章主要介紹了vuex+axios+element-ui實現(xiàn)頁面請求loading操作,結(jié)合實例形式分析了vuex+axios+element-ui實現(xiàn)頁面請求過程中l(wèi)oading遮罩層相關(guān)操作技巧與使用注意事項,需要的朋友可以參考下2020-02-02unplugin-auto-import的配置以及eslint報錯解決詳解
unplugin-auto-import?解決了vue3-hook、vue-router、useVue等多個插件的自動導(dǎo)入,也支持自定義插件的自動導(dǎo)入,是一個功能強大的typescript支持工具,這篇文章主要給大家介紹了關(guān)于unplugin-auto-import的配置以及eslint報錯解決的相關(guān)資料,需要的朋友可以參考下2022-08-08