index.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div>
  3. <svg-icon :className="className" :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. props:{
  11. className: {
  12. type: String,
  13. default: ''
  14. },
  15. },
  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.enabled) {
  30. this.$message({
  31. message: 'you browser can not work',
  32. type: 'warning'
  33. })
  34. return false
  35. }
  36. screenfull.toggle()
  37. },
  38. change() {
  39. this.isFullscreen = screenfull.isFullscreen
  40. },
  41. init() {
  42. if (screenfull.enabled) {
  43. screenfull.on('change', this.change)
  44. }
  45. },
  46. destroy() {
  47. if (screenfull.enabled) {
  48. screenfull.off('change', this.change)
  49. }
  50. }
  51. }
  52. }
  53. </script>
  54. <style scoped>
  55. .screenfull-svg {
  56. display: inline-block;
  57. cursor: pointer;
  58. fill: #5a5e66;
  59. width: 20px;
  60. height: 20px;
  61. vertical-align: 10px;
  62. }
  63. </style>