当前位置:   article > 正文

vue3前端实现全屏显示,元素垂直填满页面_elementuiplus 全屏

elementuiplus 全屏

1、 toggleFullscreen方法实现选定元素全屏展示

2、使用flex属性+ flex-direction 实现垂直布局填满整个页面

  1. <template>
  2. <div id="aaa" class="container">
  3. <div class="header">
  4. <el-button @click="toggleFullscreen">全屏</el-button>
  5. </div>
  6. <div class="content">
  7. <div style="display: flex;height: 100%">
  8. <el-table :data="countData" border style="width: 30%" height="88%">
  9. <el-table-column label="线体" prop="prolineCode" align="center" min-width="120px" />
  10. <el-table-column label="点检异常次数" prop="count" align="center" min-width="120px" />
  11. </el-table>
  12. <div id="bbb" style="width: 70%; height: 100%"></div>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import { ref, onMounted, onUnmounted } from 'vue'
  19. import * as echarts from 'echarts'
  20. export default {
  21. name: 'App',
  22. setup() {
  23. const countData = ref([])
  24. onMounted(() => {
  25. initChart()
  26. // initChart1()
  27. })
  28. onUnmounted(() => {
  29. })
  30. const initChart = () => {
  31. var chartDom = document.getElementById('bbb')
  32. let myChart = echarts.getInstanceByDom(chartDom);
  33. if (myChart) {
  34. myChart.dispose();
  35. }
  36. myChart = echarts.init(chartDom);
  37. var option = {
  38. xAxis: {
  39. type: 'category',
  40. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  41. },
  42. yAxis: {
  43. type: 'value'
  44. },
  45. series: [
  46. {
  47. data: [820, 932, 901, 934, 1290, 1330, 1320],
  48. type: 'line',
  49. smooth: true
  50. }
  51. ]
  52. }
  53. option && myChart.setOption(option)
  54. window.addEventListener('resize', function () {
  55. myChart.resize()
  56. })
  57. }
  58. const initChart1 = () => {
  59. var chartDom = document.getElementById('ccc')
  60. let myChart = echarts.getInstanceByDom(chartDom);
  61. if (myChart) {
  62. myChart.dispose();
  63. }
  64. myChart = echarts.init(chartDom);
  65. var option = {
  66. xAxis: {
  67. type: 'category',
  68. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  69. },
  70. yAxis: {
  71. type: 'value'
  72. },
  73. series: [
  74. {
  75. data: [820, 932, 901, 934, 1290, 1330, 1320],
  76. type: 'line',
  77. smooth: true
  78. }
  79. ]
  80. }
  81. option && myChart.setOption(option)
  82. window.addEventListener('resize', function () {
  83. myChart.resize()
  84. })
  85. }
  86. const toggleFullscreen = () => {
  87. const element = document.getElementById('aaa')
  88. if (element) {
  89. if (document.fullscreenElement) {
  90. document.exitFullscreen();
  91. } else {
  92. element.requestFullscreen()
  93. .catch(err => {
  94. console.log('无法进入全屏模式:', err)
  95. })
  96. }
  97. }
  98. }
  99. return {
  100. countData,
  101. toggleFullscreen
  102. }
  103. }
  104. }
  105. </script>
  106. <style>
  107. body {
  108. margin: 0;
  109. }
  110. /* 使用flex布局 */
  111. .container {
  112. display: flex;
  113. flex-direction: column;
  114. height: 100vh;
  115. /* 确保容器元素的高度与视口高度一致 */
  116. }
  117. /* 设置上部元素 */
  118. .header {
  119. border: 1px solid green;
  120. height: 100px;
  121. /* 上部元素的高度 */
  122. background-color: #ccc;
  123. /* 上部元素的样式 */
  124. }
  125. /* 设置下部元素 */
  126. .content {
  127. border: 1px solid yellow;
  128. flex-grow: 1;
  129. /* 下部元素占据父元素的剩余空间 */
  130. background-color: #eee;
  131. /* 下部元素的样式 */
  132. }
  133. </style>

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

闽ICP备14008679号