项目中有点击按钮实现全屏功能
方式一:js实现全屏
1
2
3
4
5
|
<template>
<div>
<a-button type= "primary" @click= "screen" >全屏</a-button>
</div>
</template>
|
data:
1
2
3
4
5
|
data() {
return {
fullscreen: false
};
},
|
methods:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
screen() {
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;
},
|
方式二:使用的是sreenfull插件,执行命令安装
1
|
npm install --save screenfull
|
在使用的页面正确引入:
1
|
import screenfull from ‘screenfull'
|
代码如下:
1
2
3
4
5
|
<template>
<div>
<a-button type= "primary" @click= "screen" >全屏</a-button>
<div>
</template>
|
data:
1
2
3
4
5
|
data() {
return {
fullscreen: false
};
},
|
methods:
1
2
3
4
5
6
7
8
9
|
screen() {
// 如果不允许进入全屏,发出不允许提示
if (!screenfull.enabled) {
this .$message( "您的浏览器不能全屏" );
return false ;
}
screenfull.toggle();
this .$message.success( "全屏啦" );
},
|
效果图:
实用
到此这篇关于vue中实现点击变成全屏的多种方法的文章就介绍到这了,更多相关vue点击全屏内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/ZiChen_Jiang/article/details/108748631