vue中全屏screenfull.js的使用 (默认全屏显示 使用 .request() )
请记住,浏览器仅在由用户事件(如单击,触摸,按键)启动时才进入全屏显示。
·
暂时实现 但是也有问题 官网说明注意, 如下图:
请记住,浏览器仅在由用户事件(如单击,触摸,按键)启动时才进入全屏显示。
<template>
<div>
<svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click" />
</div>
</template>
<script>
import screenfull from 'screenfull'
export default {
name: 'Screenfull',
data() {
return {
isFullscreen: false
}
},
mounted() {
this.init()
},
beforeDestroy() {
this.destroy()
},
methods: {
click() {
if (!screenfull.enabled) {
this.$message({
message: 'you browser can not work',
type: 'warning'
})
return false
}
screenfull.toggle()
},
change() {
this.isFullscreen = screenfull.isFullscreen
},
init() {
if (screenfull.enabled) {
screenfull.request() // 默认全屏显示
screenfull.on('change', this.change)
}
},
destroy() {
if (screenfull.enabled) {
screenfull.off('change', this.change)
}
}
}
}
</script>
<style scoped>
.screenfull-svg {
display: inline-block;
cursor: pointer;
fill: #5a5e66;
width: 20px;
height: 20px;
vertical-align: 10px;
}
</style>
更多推荐
已为社区贡献6条内容
所有评论(0)