vue中如何实现点击按钮 页面全屏与缩放的功能【附代码】

今天爱分享给大家带来vue中如何实现点击按钮 页面全屏与缩放的功能【附代码】,希望能够帮助到大家。

方式一:js实现全屏

<template>
<div>
<a-button type=”primary” @click=”screen”>全屏</a-button>
</div>
</template>

data:

 data() {
    return {
      fullscreen: false
    };
  },

methods:

 screen() {
      let element = document.documentElement;
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen();
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen();
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen();
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen();
        }
      }
      this.fullscreen = !this.fullscreen;
    },

方式二:使用的是sreenfull插件,执行命令安装

npm install --save screenfull

在使用的页面正确引入:

import screenfull from ‘screenfull’

代码如下:

<template>
<div>
<a-button type=”primary” @click=”screen”>全屏</a-button>
<div>
</template>

data:

 data() {
    return {
      fullscreen: false
    };
  },

methods:

screen() {
      // 如果不允许进入全屏,发出不允许提示
      if (!screenfull.enabled) {
        this.$message("您的浏览器不能全屏");
        return false;
      }
      screenfull.toggle();
      this.$message.success("全屏啦");
    },

效果图:

人已赞赏
前端

Props with type Object/Array must use a factory function to return the default value【解决办法】

2020-11-11 9:53:04

前端

Invalid prop: type check failed for prop “model“. Expected Object, got Array【解决办法】

2020-11-11 10:26:19

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
'); })();