index.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div>
  3. <svg-icon class-name="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. console.log(screenfull)
  24. if (!screenfull.isEnabled) {
  25. this.$message({
  26. message: 'you browser can not work',
  27. type: 'warning'
  28. })
  29. return false
  30. }
  31. screenfull.toggle()
  32. },
  33. change() {
  34. this.isFullscreen = screenfull.isFullscreen
  35. },
  36. init() {
  37. if (screenfull.enabled) {
  38. screenfull.on('change', this.change)
  39. }
  40. },
  41. destroy() {
  42. if (screenfull.enabled) {
  43. screenfull.off('change', this.change)
  44. }
  45. }
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. .icon {
  51. cursor: pointer;
  52. font-size: 12px;
  53. vertical-align: middle;
  54. }
  55. .screenfull-svg {
  56. display: inline-block;
  57. cursor: pointer;
  58. fill: #5a5e66;
  59. ;
  60. width: 20px;
  61. height: 20px;
  62. vertical-align: 10px;
  63. }
  64. </style>