当前位置: 首页 > news >正文

vue实现全屏screenfull-封装组件

1. 安装依赖

npm install --save screenfull

2. 引用

import screenfull from "screenfull"

3.封装fullScreen/index:

<template><div><el-tooltip v-if="!content" effect="dark" :content="fullscreenTips" placement="bottom"><i class="el-icon-full-screen" @click="handleFullscreenClick"></i></el-tooltip></div>
</template><script>
import screenfull from 'screenfull'export default {props: {element: {type: String,default: 'html'},openTips: {type: String,default: 'Fullscreen'},exitTips: {type: String,default: 'Exit Fullscreen'},content: {type: Boolean,default: false}},data() {return {isFullscreen: false};},computed: {fullscreenTips() {return this.isFullscreen ? this.exitTips : this.openTips;},},methods: {handleFullscreenClick() {const dom = document.querySelector(this.element) || undefined;if (screenfull.enabled) {screenfull.toggle(dom);this.isFullscreen = screenfull.isFullscreen;}},handleFullscreenChange() {this.isFullscreen = screenfull.isFullscreen;// Clear all classes when exiting fullscreenif (!this.isFullscreen) {document.body.className = '';}},handleKeyDown(event) {// 检查是否按下了 ESC 键if (event.key === 'Escape' && screenfull.isFullscreen) {this.$message.warning('按 ESC 键可以退出全屏模式');}}},mounted() {if (screenfull.enabled) {screenfull.on('change', this.handleFullscreenChange);document.addEventListener('keydown', this.handleKeyDown);}},beforeDestroy() {if (screenfull.enabled) {screenfull.off('change', this.handleFullscreenChange);document.removeEventListener('keydown', this.handleKeyDown);}}
};
</script>

4.vue页面使用

<template><div class="warpper" style="" id="digital-screen"><div class="chartTitle"><div class="logo"> 2024年6月17日 </div><div class="name"> 易恒智能模糊测试系统数据监控 </div><div class="time"><Screenfull class="right-menu-item" :element="'#digital-screen'"/></div></div>
</div>

全屏的按钮根据实际需求更换!

very easy!!!

相关文章:

  • 【尝鲜】SpringCloudAlibaba AI 配置使用教程
  • docker封禁对外端口映射
  • xcode报错合集,你都遇到过哪些跳不过的坑
  • 【C++ 11 新特性】lambda 表达式详解
  • 【后端】websocket学习笔记
  • LabVIEW电子类实验虚拟仿真系统
  • 《web应用技术》第十一次课后作业
  • git创建子模块
  • (微服务实战)预付卡平台支付交易系统卡充值业务流程设计
  • 格雷母线技术革新:推动斗轮堆取料机进入精准操作时代
  • 人工智能--自然语言处理NLP概述
  • GD32F4xx 移植agile_modbus软件包与电能表通信
  • 怎么把webp文件转换为jpg?快来试试这四种转换方法!
  • 简单剖析tRPC-Go中使用的第三方协程池ants
  • 精读文献|《CATENA》新文:全球植被绿化对生态系统水分利用效率的响应
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • 345-反转字符串中的元音字母
  • cookie和session
  • CSS 三角实现
  • express + mock 让前后台并行开发
  • gf框架之分页模块(五) - 自定义分页
  • Javascript基础之Array数组API
  • JS题目及答案整理
  • MD5加密原理解析及OC版原理实现
  • PAT A1092
  • Tornado学习笔记(1)
  • Webpack 4x 之路 ( 四 )
  • 复习Javascript专题(四):js中的深浅拷贝
  • 技术发展面试
  • 聚类分析——Kmeans
  • 漫谈开发设计中的一些“原则”及“设计哲学”
  • 通过来模仿稀土掘金个人页面的布局来学习使用CoordinatorLayout
  • 小试R空间处理新库sf
  • 正则与JS中的正则
  • 【干货分享】dos命令大全
  • Hibernate主键生成策略及选择
  • RDS-Mysql 物理备份恢复到本地数据库上
  • 积累各种好的链接
  • 浅谈sql中的in与not in,exists与not exists的区别
  • ​必胜客礼品卡回收多少钱,回收平台哪家好
  • #{}和${}的区别是什么 -- java面试
  • #FPGA(基础知识)
  • (9)YOLO-Pose:使用对象关键点相似性损失增强多人姿态估计的增强版YOLO
  • (C语言)编写程序将一个4×4的数组进行顺时针旋转90度后输出。
  • (k8s)kubernetes 部署Promehteus学习之路
  • (void) (_x == _y)的作用
  • (太强大了) - Linux 性能监控、测试、优化工具
  • (转) Face-Resources
  • (转)使用VMware vSphere标准交换机设置网络连接
  • (转载)(官方)UE4--图像编程----着色器开发
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .NET CORE 2.0发布后没有 VIEWS视图页面文件
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .Net 中Partitioner static与dynamic的性能对比
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证