index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <span :title="isFullscreen ? '退出全屏' : '进入全屏'">
  3. <vab-icon
  4. :icon="[
  5. 'fas',
  6. isFullscreen ? 'compress-arrows-alt' : 'expand-arrows-alt',
  7. ]"
  8. @click="click"
  9. ></vab-icon>
  10. </span>
  11. </template>
  12. <script>
  13. import screenfull from 'screenfull'
  14. export default {
  15. name: 'VabFullScreenBar',
  16. data() {
  17. return {
  18. isFullscreen: false,
  19. }
  20. },
  21. mounted() {
  22. this.init()
  23. },
  24. beforeDestroy() {
  25. this.destroy()
  26. },
  27. methods: {
  28. click() {
  29. if (!screenfull.isEnabled) {
  30. this.$baseMessage('开启全屏失败', 'error')
  31. return false
  32. }
  33. screenfull.toggle()
  34. this.$emit('refresh')
  35. },
  36. change() {
  37. this.isFullscreen = screenfull.isFullscreen
  38. },
  39. init() {
  40. if (screenfull.isEnabled) {
  41. screenfull.on('change', this.change)
  42. }
  43. },
  44. destroy() {
  45. if (screenfull.isEnabled) {
  46. screenfull.off('change', this.change)
  47. }
  48. },
  49. },
  50. }
  51. </script>