need
Click on the image to enlarge
Can close the enlarged image
download
cnpm in viewerjs
Status Management + Methods
stores/
import { defineStore } from 'pinia' export const imgSeeStore = defineStore('imgSeeStore', { state: () => ({ showImgSee: false, ImgUrl: '', }), getters: { }, actions: { openImgShow(url) { = url = true }, resetSeeImg() { = '' = false } } })
Encapsulated components
<template> <img ref="el" :src="ImgUrl" /> </template> <script setup> import "viewerjs/dist/"; import Viewer from "viewerjs"; import { nextTick, onMounted, ref } from "vue"; import { storeToRefs } from "pinia"; import { globalStateStore } from "src/stores/globalState"; const useGlobalStateStore = globalStateStore(), { ImgUrl } = storeToRefs(useGlobalStateStore), { resetSeeImg } = useGlobalStateStore; const el = ref(); onMounted(async () => { await nextTick(); // Picture viewer shutdown event ("hide", () => resetSeeImg()); new Viewer(, { navbar: false, title: false, }).show(); }); </script>
use
<template> <!-- This is the picture to view --> <img style="max-width: 200px" :src="img" @click="openImgShow(img)" /> <img-see v-if="showImgSee" /> </template> <script setup> import { ref} from "vue"; import { storeToRefs } from "pinia"; import ImgSee from "src/components/"; import { imgSeeStore} from "src/stores/imgSeeStore"; const img = ref('/public/') const useImgSeeStore= imgSeeStore(), { showImgSee } = storeToRefs(useImgSeeStore), { openImgShow } = useImgSeeStore; </script>
This is the end of this article about implementing image viewer based on Vue3 packaging. For more related content of Vue3 image viewer, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!