index.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div>
  3. <svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click" />
  4. </div>
  5. </template>
  6. <script>
  7. import screenfull from 'screenfull'
  8. export default {
  9. name: 'Screenfull',
  10. data() {
  11. return {
  12. isFullscreen: false
  13. }
  14. },
  15. mounted() {
  16. this.init()
  17. },
  18. beforeDestroy() {
  19. this.destroy()
  20. },
  21. methods: {
  22. click() {
  23. if (!screenfull.isEnabled) {
  24. this.$message({ message: '你的浏览器不支持全屏', type: 'warning' })
  25. return false
  26. }
  27. screenfull.toggle()
  28. },
  29. change() {
  30. this.isFullscreen = screenfull.isFullscreen
  31. },
  32. init() {
  33. if (screenfull.isEnabled) {
  34. screenfull.on('change', this.change)
  35. }
  36. },
  37. destroy() {
  38. if (screenfull.isEnabled) {
  39. screenfull.off('change', this.change)
  40. }
  41. }
  42. }
  43. }
  44. </script>
  45. <style scoped>
  46. .screenfull-svg {
  47. display: inline-block;
  48. cursor: pointer;
  49. fill: #5a5e66;;
  50. width: 20px;
  51. height: 20px;
  52. vertical-align: 10px;
  53. }
  54. </style>