【Viewer.js】vue3封装图片查看器

server/2025/2/25 23:48:51/

效果图

在这里插入图片描述

需求

  • 点击图片放大
  • 可关闭放大的 图片

下载

cnpm in viewerjs

状态管理+方法

stores/imgSeeStore.js

import { defineStore } from 'pinia'
export const imgSeeStore = defineStore('imgSeeStore', {state: () => ({showImgSee: false,ImgUrl: '',}),getters: {},actions: {openImgShow(url) {this.ImgUrl = urlthis.showImgSee = true},resetSeeImg() {this.ImgUrl = ''this.showImgSee = false}}
})

封装的组件

<template><img ref="el" :src="ImgUrl" />
</template><script setup>javascript">
import "viewerjs/dist/viewer.css";
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();//   图片查看器关闭事件el.value.addEventListener("hide", () => resetSeeImg());new Viewer(el.value, {navbar: false,title: false,}).show();
});
</script>

使用

TestVue.vue

<template><!-- 这个是要点击查看的图片 --><img style="max-width: 200px" :src="img"@click="openImgShow(img)"/><img-see v-if="showImgSee" />
</template><script setup>javascript">
import { ref} from "vue";
import { storeToRefs } from "pinia";
import ImgSee from "src/components/ImgSee.vue";
import { imgSeeStore} from "src/stores/imgSeeStore";  const img = ref('/public/test.jpg')
const useImgSeeStore= imgSeeStore(),{ showImgSee } = storeToRefs(useImgSeeStore),{ openImgShow } = useImgSeeStore;
</script>

http://www.ppmy.cn/server/170632.html

相关文章

2025最新Python机器视觉实战:基于OpenCV与深度学习的多功能工业视觉检测系统(附完整代码)

2025最新Python机器视觉实战:基于OpenCV与深度学习的多功能工业视觉检测系统(附完整代码) 摘要:本文基于OpenCV与深度学习模型,实现一个多功能工业视觉检测系统,包含缺陷检测、尺寸测量、颜色识别、OCR文本识别、目标分类与数据可视化等功能。代码兼容Python 3.7+,功能…

微信小程序——访问服务器媒体文件的实现步骤

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;趣享先生的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏&…

Matplotlib | 一文搞定Matplotlib从入门到实战演练!

文章目录 1 什么是Matplotlib1.1 Matplotlib的安装1.2 Matplotlib的基本使用 2 绘制直线3 绘制折线设置标签文字和线条粗细设置中文标题风格的设置 4 绘制曲线绘制曲线yx^2绘制正弦曲线和余弦曲线画布分区 5 绘制散点图绘制不同种类不同颜色的线 6 绘制条形图&#xff08;柱状&…

Redis 缓存穿透、击穿、雪崩:问题与解决方案

在使用 Redis 作为缓存中间件时&#xff0c;系统可能会面临一些常见的问题&#xff0c;如 缓存穿透、缓存击穿 和 缓存雪崩。这些问题如果不加以解决&#xff0c;可能会导致数据库压力过大、系统响应变慢甚至崩溃。本文将详细分析这三种问题的起因&#xff0c;并提供有效的解决…

ubuntu

网络 ping 第29个包丢了 ifconfig route -n 路由表 Destination&#xff1a;目的地址 Gateay&#xff1a;网关 Genmask&#xff1a;掩码 Flags&#xf…

使用Selenium和ChromeDriver模拟用户操作:从表单填写到数据提交

第一幕&#xff1a;危机四伏的投票战场 场景&#xff1a;深夜的科技公司办公室&#xff0c;工程师小王盯着屏幕上闪烁的代码&#xff0c;产品经理莉莉焦急地踱步。 莉莉&#xff08;扶额&#xff09;&#xff1a; “小王&#xff0c;无人机市场调研的投票数据必须今晚拿到&…

登录-12.Interceptor-详解

一.拦截器-拦截路径 配置拦截除了"/login"登录请求以外的所有请求。下面我们进行演示。首先演示登录。 当前返回值中没有输出任何定义拦截器时preHandle&#xff0c;postHandle和afterCompletion的输出信息&#xff0c;因此可以知道拦截器Interceptor并没有生效&…

【R包】tidyplots----取代ggplot2的科研绘图利器

文章目录 介绍安装Usage文档参考 介绍 tidyplots----取代ggplot2的科研绘图利器。tidyplots的目标是简化为科学论文准备出版的情节的创建。它允许使用一致和直观的语法逐渐添加&#xff0c;删除和调整情节组件。 安装 You can install the released version of tidyplots fro…