vue uses screenfull plug in to realize full screen function

  • 2021-08-21 19:39:27
  • OfStack

This article example for everyone to share vue using screenfull plug-in to achieve full-screen function of the specific code, for your reference, the specific content is as follows

1. Install screenfull. js plug-in (available on npm official website)


npm install screenfull --save

2. In the vue project, src/components/ScreenFull/index. vue (written as a common component)


<template>
 <el-tooltip effect="dark" content=" Full screen " placement="bottom">
  <img @click="screen" class="pointer" :src="require('@/assets/images/screenful.png')" :width="width" :height="height">
 </el-tooltip>
</template>

<script>
import screenfull from 'screenfull'
export default {
 name: 'screenful',
 components: {
 },
 props: {
  width: {
   type: Number,
   default: 20
  },
  height: {
   type: Number,
   default: 20
  }
 },
 data() {
  return {
  }
 },
 computed: {
 },
 watch: {
 },
 methods: {
  screen() {
   if (!screenfull.isEnabled) {
    this.$message({
     message: 'you browser can not work',
     type: 'warning'
    })
    return false
   }
   screenfull.toggle()
  }
 },
 created() {
 },
 mounted() {
 }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
</style>

3. Use the screenful component


<template>
  <screenfull class="ml64" :width="20" :height="20"></screenfull>
</template>
<script>
import screenfull from '@/components/ScreenFull'
export default {
 name: 'navbar',
 components: {
  screenfull
 },
 data() {
  return {
  }
 },
 computed: {
 },
 watch: {
 },
 methods: {
 },
 created() {
 },
 mounted() {
 }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
</style>

Related articles: