首页 > 其他分享 >封装大屏组件 screenfull

封装大屏组件 screenfull

时间:2022-11-08 09:56:56浏览次数:39  
标签:index 封装 js 组件 ScreenFull 大屏 screenfull change

错误场景:使用大屏插件 screenFull 报错:in ./node_modules/screenfull/index.js  Module parse failed: Unexpected token (59:42) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

查错 :

1. 重新启动 npm run dev 

2. 删除 node_modules重新 yarn 安装 

3. 使用screenFull组件出错 ;

  标准流程 :yarn add  [email protected]

  1. 封装组件 :src/components/ScreenFull/index.vue

组件代码:

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

<script>
import screenfull from 'screenfull'

export default {
  name: 'Screenfull',
  data() {
    return {
      isFullscreen: false
    }
  },
  mounted() {
    this.init()
  },
  beforeDestroy() {
    this.destroy()
  },
  methods: {
    click() {
      if (!screenfull.enabled) {
        this.$message({
          message: 'you browser can not work',
          type: 'warning'
        })
        return false
      }
      screenfull.toggle()
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off('change', this.change)
      }
    }
  }
}
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>

2. 注册组件 全局注册该组件 src/components/index.js

import ScreenFull from './ScreenFull'
Vue.component('ScreenFull', ScreenFull) // 注册全屏组件

3. 把 放在 template 模板标签里面

<screen-full class="right-menu-item" />
样式:
.right-menu-item {
   vertical-align: middle;  /*  修改为middle */
}
 

标签:index,封装,js,组件,ScreenFull,大屏,screenfull,change
From: https://www.cnblogs.com/zhulongxu/p/16868670.html

相关文章