当前位置:   article > 正文

前端可视化大屏设置全屏模式方法_前端全屏切换

前端全屏切换

目录

1.效果举例:

         2.场景

3.实现步骤 


1.效果举例:

点击tab栏进入全屏 

按esc或者屏幕中间图标退出全屏,通过返回按钮返回项目 

 

 


2.场景

相当于手动按F11的效果。经典的应用场景是制作可视化大屏或者全屏展示类的页面。因为现在写的是vue项目,所以稍后以vue为例子。


3.实现步骤 

第一步,下载插件

npm install screenfull  save

第二步,在你需要使用的页面中引入

  1. //引入全屏插件
  2. import screenfull from "screenfull";

第三步,复制下面的函数

  1. methods: {
  2. //全屏方法
  3. isScreenFull () {
  4. if (!screenfull.isEnabled) {
  5. // 如果不支持进入全屏,发出不支持提示
  6. this.$message({
  7. message: "您的浏览器版本过低不支持全屏显示!",
  8. type: "warning"
  9. })
  10. return false
  11. }
  12. screenfull.toggle()
  13. }
  14. },

第四步,页面的结构里面找个位置粘贴以下代码

注意一个点,样式设置为绝对定位之类的,意思是别让他占位置影响布局。

  1. <screenfull
  2. style="position: absolute; left: 0px; top: 0px; z-index: 9999999"
  3. id="screenfull"
  4. @click="isScreenFull"
  5. >
  6. <el-button style="display: none">全屏</el-button></screenfull >

第五步,生命周期中调用,达到一进入就自动全屏

  1. created () {
  2. this.$nextTick(() => {
  3. this.isScreenFull() //以下两种方式二选一,均可
  4. // setTimeout(() => {
  5. // document.querySelector("#screenfull").click()
  6. // })
  7. })
  8. },

至此,结束。

附上一个设置返回功能的写法,以供参考

  1. <template>
  2. <div>
  3. <div id="app" v-if="!idBig">
  4. <router-view v-if="isRouterAlive" />
  5. </div>
  6. <div v-if="idBig">
  7. <el-button @click="$router.go(-1) || $router.push('/employees')"
  8. >返回</el-button
  9. >
  10. <BigPing></BigPing>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'App',
  17. provide () {
  18. return {
  19. reload: this.reload
  20. }
  21. },
  22. data () {
  23. return {
  24. idBig: false,
  25. isRouterAlive: true
  26. }
  27. },
  28. created () {
  29. },
  30. methods: {
  31. reload () {
  32. this.isRouterAlive = false
  33. this.$nextTick(function () {
  34. this.isRouterAlive = true
  35. })
  36. },
  37. },
  38. watch: {
  39. $route (to, from) {
  40. if (to.name == 'Dashboard') {
  41. this.idBig = true
  42. } else {
  43. this.idBig = false
  44. }
  45. }
  46. },
  47. }
  48. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/283566
推荐阅读
相关标签
  

闽ICP备14008679号