我是励志哥

vue实现全屏效果

方式一:js实现全屏

<template>
 <div>
   <a-button type="primary" @click="screen">全屏</a-button>
 </div>
</template>

data() {
 return {
  fullscreen: false
 };
},

methods:{
    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插件,执行命令安装

下载
npm install --save screenfull
在页面引入
import screenfull from ‘screenfull'


<template>
   <div>
     <a-button type="primary" @click="screen">全屏</a-button>
   <div>
</template>

data() {
 return {
  fullscreen: false
 };
},

methods:{
    screen() {
   screenfull.toggle();
  
  },

}

 

posted @ 2021-11-09 09:34  python黑客编程  阅读(931)  评论(0编辑  收藏  举报