暂时实现 但是也有问题 官网说明注意, 如下图:
请记住,浏览器仅在由用户事件(如单击,触摸,按键)启动时才进入全屏显示。

在这里插入图片描述

<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>

Logo

前往低代码交流专区

更多推荐