Vue全屏效果 Vue使用screenfull实现全屏效果
LSG199800 人气:1想了解Vue使用screenfull实现全屏效果的相关内容吗,LSG199800在本文为您仔细讲解Vue全屏效果的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:vue,screenfull,全屏,下面大家一起来学习吧。
安装
npm install --save screenfull
在需要的页面引用
import screenfull from 'screenfull'
全屏使用
<template> <span @click='clickFullscreen'>全屏</span> </template> <script> import screenfull from 'screenfull' export default{ name: 'screenfull', data(){ return { isFullscreen: false } }, methods:{ clickFullscreen(){ if (!screenfull.isEnabled) { this.$message({ message: 'you browser can not work', type: 'warning' }) return false } screenfull.toggle() } } } </script>
原生实现方法
// 全屏事件 兼容 clickFullscreen() { let element = document.documentElement; if (this.isFullscreen) { 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.isFullscreen= !this.isFullscreen; }
加载全部内容