1、 toggleFullscreen方法实现选定元素全屏展示文章来源:https://www.toymoban.com/news/detail-792730.html
2、使用flex属性+ flex-direction 实现垂直布局填满整个页面文章来源地址https://www.toymoban.com/news/detail-792730.html
<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>
到了这里,关于vue3前端实现全屏显示,元素垂直填满页面的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!