vue3 全屏

<template>
  <button @click="toggleFullScreen">Toggle Full Screen</button>
</template>
 
<script setup>
import { ref } from 'vue';
 
const isFullScreen = ref(false);
 
const toggleFullScreen = () => {
  if (!document.fullscreenElement && !isFullScreen.value) {
    // 进入全屏
    document.documentElement.requestFullscreen().then(() => {
      isFullScreen.value = true;
    });
  } else {
    // 退出全屏
    if (document.exitFullscreen) {
      document.exitFullscreen().then(() => {
        isFullScreen.value = false;
      });
    }
  }
};
</script>

 

posted @ 2024-08-05 17:17  林财钦  阅读(31)  评论(0编辑  收藏  举报