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

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

<template>
  <div id="aaa" class="container">
    <div class="header">
      <el-button @click="toggleFullscreen">全屏</el-button>
    </div>
    <div class="content">
      <div style="display: flex;height: 100%">
        <el-table :data="countData" border style="width: 30%" height="88%">
          <el-table-column label="线体" prop="prolineCode" align="center" min-width="120px" />
          <el-table-column label="点检异常次数" prop="count" align="center" min-width="120px" />
        </el-table>
        <div id="bbb" style="width: 70%; height: 100%"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, onUnmounted } from 'vue'
import * as echarts from 'echarts'
export default {
  name: 'App',
  setup() {
    const countData = ref([])

    onMounted(() => {
      initChart()
      // initChart1()
    })

    onUnmounted(() => {
    })

    const initChart = () => {
      var chartDom = document.getElementById('bbb')
      let myChart = echarts.getInstanceByDom(chartDom);
      if (myChart) {
        myChart.dispose();
      }
      myChart = echarts.init(chartDom);
      var option = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: 'line',
            smooth: true
          }
        ]
      }
      option && myChart.setOption(option)
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    }

    const initChart1 = () => {
      var chartDom = document.getElementById('ccc')
      let myChart = echarts.getInstanceByDom(chartDom);
      if (myChart) {
        myChart.dispose();
      }
      myChart = echarts.init(chartDom);
      var option = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: 'line',
            smooth: true
          }
        ]
      }
      option && myChart.setOption(option)
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    }

    const toggleFullscreen = () => {
      const element = document.getElementById('aaa')
      if (element) {
        if (document.fullscreenElement) {
          document.exitFullscreen();
        } else {
          element.requestFullscreen()
            .catch(err => {
              console.log('无法进入全屏模式:', err)
            })
        }
      }
    }

    return {
      countData,
      toggleFullscreen
    }
  }
}
</script>

<style>
body {
  margin: 0;
}

/* 使用flex布局 */
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* 确保容器元素的高度与视口高度一致 */
}

/* 设置上部元素 */
.header {
  border: 1px solid green;
  height: 100px;
  /* 上部元素的高度 */
  background-color: #ccc;
  /* 上部元素的样式 */
}

/* 设置下部元素 */
.content {
  border: 1px solid yellow;
  flex-grow: 1;
  /* 下部元素占据父元素的剩余空间 */
  background-color: #eee;
  /* 下部元素的样式 */
}
</style>

GitHub 加速计划 / vu / vue
207.55 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:3 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 5 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐