<template>
  <div @click="onToggle">
    <svg-icon :icon="isFullscreen ? 'exit-fullscreen' : 'fullscreen'">
    </svg-icon>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import screenfull from 'screenfull'

//是否全屏
const isFullscreen = ref(false)

//触发事件
const onToggle = () => {
  screenfull.toggle()
}

//监听
const change = () => {
  isFullscreen.value = screenfull.isFullscreen
}

//绑定监听
onMounted(() => {
  screenfull.on('change', change)
})
//取消监听
onUnmounted(() => {
  screenfull.off('change', change)
})
</script>

<style></style>
