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

ops/2025/2/24 22:57:11/

效果图

在这里插入图片描述

需求

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

下载

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/ops/161056.html

相关文章

【AI】VS Code中使用GitHub Copilot

在VS Code中使用GitHub Copilot可以显著提升开发效率和代码质量&#xff0c;以下是其主要优势&#xff1a; 1. 代码自动补全 智能建议&#xff1a;Copilot能根据上下文提供代码补全建议&#xff0c;减少手动输入。 多语言支持&#xff1a;支持多种编程语言&#xff0c;适用于不…

Spring Boot 集成 T-io 实现客户端服务器通信

Spring Boot 集成 T-io 实现客户端服务器通信 本文详细介绍如何在 Spring Boot 项目中集成 T-io 框架&#xff0c;实现客户端与服务器之间的通信&#xff0c;并支持组聊、群聊和私聊功能。通过本文&#xff0c;您能够全面了解 T-io core 的使用方法&#xff0c;以及如何正确启…

Python学习总结

客户端与服务端聊天窗口 服务端 导入 wxPython 用于创建图形界面。 socket 用于网络通信&#xff0c;AF_INET 是 IPv4 地址族&#xff0c;SOCK_STREAM 表示流式套接字&#xff08;TCP&#xff09;。 利用wxPython 创建图形界面&#xff0c;并通过 socket 与服务器通信。 主要…

Git 工作流程

1、Git 工作流程 http://www.ruanyifeng.com/blog/2015/12/git-workflow.html git push -f origin HEAD^:master 删除服务器上最近的一次提交git push -f origin HEAD^:master 2、Git分支管理 动画形式演示分支效果&#xff1a; http://onlywei.github.io/explain-git-with-…

蓝桥杯学习笔记03-滑动窗口不定长(最长/最大)

题目来源 分享丨【题单】滑动窗口与双指针&#xff08;定长/不定长/单序列/双序列/三指针/分组循环&#xff09; - 力扣&#xff08;LeetCode&#xff09; 不定长滑动窗口 2024. 考试的最大困扰度 - 力扣&#xff08;LeetCode&#xff09; 解决&#xff1a;分别处理‘T’和’…

【从0做项目】Java文档搜索引擎(9)烧脑终章!

阿华代码&#xff0c;不是逆风&#xff0c;就是我疯 你们的点赞收藏是我前进最大的动力&#xff01;&#xff01; 希望本文内容能够帮助到你&#xff01;&#xff01; 目录 文章导读 零&#xff1a;项目结果展示 一&#xff1a;导入 二&#xff1a;问题引入 1&#xff1a;情…

【DeepSeek】本地部署,保姆级教程

deepseek网站链接传送门&#xff1a;DeepSeek 在这里主要介绍DeepSeek的两种部署方法&#xff0c;一种是调用API&#xff0c;一种是本地部署。 一、API调用 1.进入网址Cherry Studio - 全能的AI助手选择立即下载 2.安装时位置建议放在其他盘&#xff0c;不要放c盘 3.进入软件后…

技术分享:MyBatis SQL 日志解析脚本

技术分享&#xff1a;MyBatis SQL 日志解析脚本 1. 脚本功能概述2. 实现细节2.1 HTML 结构2.2 JavaScript 逻辑 3. 脚本代码4. 使用方法4.1 示例 5. 总结 在日常开发中&#xff0c;使用 MyBatis 作为持久层框架时&#xff0c;我们经常需要查看 SQL 日志以调试和优化查询。然而&…