惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
腾讯CDC
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost
小众软件
小众软件
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
P
Privacy International News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
Forbes - Security
Forbes - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
Google Developers Blog
S
Secure Thoughts
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
TaoSecurity Blog
TaoSecurity Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Last Week in AI
Last Week in AI
H
Heimdal Security Blog
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
Security Latest
Security Latest
SecWiki News
SecWiki News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Security Affairs
V2EX - 技术
V2EX - 技术
S
Schneier on Security
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
博客园_首页
AI
AI
Help Net Security
Help Net Security
I
Intezer
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Exploit Database - CXSecurity.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hacker News: Ask HN
Hacker News: Ask HN
Project Zero
Project Zero
D
Docker

博客园 - 雪莉06

antd vue 树形表格 vue2 jeecgBoot keepalive 解决方案 screenfull全屏组件的基本使用 网页导出EXCEL格式数据,长数字变为科学计数法的解决方法 dedecms织梦自定义表单导出到excel的方法 织梦dede:arclist按最新修改排序orderby=pubdate无效的解决方法 vue-router报错:Uncaught (in promise) NavigationDuplicated {_name: ‘NavigationDuplicated‘, name: ‘Navig nvm的安装和使用(转) elementUI 的 input无法输入bug解决 vue数字翻牌效果 j-modal的 slot="footer" 失效 v-if判断页脚按钮 帝国CMS后台登录空白怎么办?如何修改成https ES6两个数组进行比较 element ui form表单 表格下嵌套动态表格,新增行,删除行 vue 父子组件传值报错:this.$emit is not a function 解决 dede列表页调用二三级导航栏(转载) a-table 鼠标滑过显示小手,当前行可点击(转载) echarts折线图使用dataZoom,切换数据时渲染异常,出现竖线bug vue里面修改title样式
vue中实现页面全屏和指定元素全屏
雪莉06 · 2025-07-01 · via 博客园 - 雪莉06

1.vue中如何快速实现页面的全屏?

案例1:点击fullScreen按钮(icon),实现整个页面的全屏:

代码:

<a-icon type="fullscreen" 
    style="font-size: 22px;margin-left: 10px;" 
    id="fullscreen_button" 
    @click="handleFullScreen()"
/>
export default {
	name: "index",
	data(){
		return{
			fullscreen: false
		}
	},
	methods:{
		handleFullScreen(){
			let element = document.documentElement;
			if (this.fullscreen) {
				if (document.exitFullscreen) {
					document.exitFullscreen();
				} else if (document.webkitCancelFullScreen) {
					document.webkitCancelFullScreen();
				} else if (document.mozCancelFullScreen) {
					document.mozCancelFullScreen();
				} else if (document.msExitFullscreen) {
					document.msExitFullscreen();
				}
			} else {
				if (element.requestFullscreen) {
					element.requestFullscreen();
				} else if (element.webkitRequestFullScreen) {
					element.webkitRequestFullScreen();
				} else if (element.mozRequestFullScreen) {
					element.mozRequestFullScreen();
				} else if (element.msRequestFullscreen) {
					// IE11
					element.msRequestFullscreen();
				}
			}
			this.fullscreen = !this.fullscreen;
		}
	}
}

2.vue中如何实现页面的指定元素全屏?

安装依赖(有淘宝镜像用cnpm,没有就npm):

cnpm install screenfull --save

引入需要全屏的页面中使用:

import screenfull from "screenfull"; 

给要点击实现全屏的按钮和全屏的区域元素设置id:

<a-icon type="fullscreen" 
    style="font-size: 22px;margin-left: 10px;" 
    id="fullscreen_button"/>

<div id="container_max">
    <a-row :gutter="24">
        <a-col :sm="24" :md="18" :xl="18">
            <div
               :style="{ width: '100%', height: scrollHeight - 60 + 'px', border: '1px solid #ccc', padding: '10px' }">
                <h3 style="font-weight: bolder;">图片</h3>
                <img src="../../assets/images/confImg.jpg" alt="" style="width: 100%; height: 100%;">
             </div>
        </a-col>
        <a-col :sm="24" :md="6" :xl="6">
            <div :style="{ width: '100%', height: scrollHeight - 60 + 'px', border: '1px solid #ccc', padding: '10px' }">
                <h3 style="font-weight: bolder;">视频</h3>
                <video src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" autoplay controls style="width: 100%; height: auto;"></video>
            </div>
        </a-col>
    </a-row>
</div>
mounted() {
      const element = document.getElementById('container_max');//指定全屏区域元素
      document.getElementById('fullscreen_button').addEventListener('click', () => {
        if (screenfull.isEnabled) {
          screenfull.request(element);
        }
      });//实现模块全屏
}

3.vue中如何实现全屏时候Esc按键功能?

//是否全屏并按键ESC键的方法
fullscreenElement() {
    var fullscreenEle = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement;
    return fullscreenEle;
},

全屏时候防抖:

    //全屏
    fullscreenDocument: debounce(
      function() {
        let fullHome = document.getElementById("home");
        document.getElementById("home").style.height = "100%";
        if (this.fullscreen) {
          if (document.exitFullscreen) {
            document.exitFullscreen();
          } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
          } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
          } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
          }
        } else {
          if (fullHome.requestFullscreen) {
            fullHome.requestFullscreen();
          } else if (fullHome.webkitRequestFullScreen) {
            fullHome.webkitRequestFullScreen();
          } else if (fullHome.mozRequestFullScreen) {
            fullHome.mozRequestFullScreen();
          } else if (fullHome.msRequestFullscreen) {
            // IE11
            fullHome.msRequestFullscreen();
          }
        }
        this.fullscreen = !this.fullscreen;
      },
      1000,
      { leading: true, trailing: false }
    ),