1. 安装依赖

npm install --save screenfull

2. 引用

import screenfull from "screenfull"

3.封装fullScreen/index:

<template>
  <div>
    <el-tooltip v-if="!content" effect="dark" :content="fullscreenTips" placement="bottom">
      <i class="el-icon-full-screen" @click="handleFullscreenClick"></i>
    </el-tooltip>
  </div>
</template>

<script>
import screenfull from 'screenfull'

export default {
  props: {
    element: {
      type: String,
      default: 'html'
    },
    openTips: {
      type: String,
      default: 'Fullscreen'
    },
    exitTips: {
      type: String,
      default: 'Exit Fullscreen'
    },
    content: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isFullscreen: false
    };
  },
  computed: {
    fullscreenTips() {
      return this.isFullscreen ? this.exitTips : this.openTips;
    },
  },
  methods: {
    handleFullscreenClick() {
      const dom = document.querySelector(this.element) || undefined;
      if (screenfull.enabled) {
        screenfull.toggle(dom);
        this.isFullscreen = screenfull.isFullscreen;
      }
    },
    handleFullscreenChange() {
      this.isFullscreen = screenfull.isFullscreen;
      // Clear all classes when exiting fullscreen
      if (!this.isFullscreen) {
        document.body.className = '';
      }
    },
    handleKeyDown(event) {
      // 检查是否按下了 ESC 键
      if (event.key === 'Escape' && screenfull.isFullscreen) {
        this.$message.warning('按 ESC 键可以退出全屏模式');
      }
    }
  },
  mounted() {
    if (screenfull.enabled) {
      screenfull.on('change', this.handleFullscreenChange);
      document.addEventListener('keydown', this.handleKeyDown);
    }
  },
  beforeDestroy() {
    if (screenfull.enabled) {
      screenfull.off('change', this.handleFullscreenChange);
      document.removeEventListener('keydown', this.handleKeyDown);
    }
  }
};
</script>

4.vue页面使用

<template>
  <div class="warpper" style="" id="digital-screen">
    <div class="chartTitle">
      <div class="logo"> 2024年6月17日 </div>
      <div class="name"> 易恒智能模糊测试系统数据监控 </div>
      <div class="time">
        <Screenfull class="right-menu-item" :element="'#digital-screen'"/>
      </div>
    </div>
</div>

全屏的按钮根据实际需求更换!

very easy!!!

GitHub 加速计划 / vu / vue
80
16
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:4 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 6 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 6 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐