vue3-elementPlus 全屏小组件

1.创建fullScreen.vue

<template>
  <div class="com">
    <el-icon>
      <FullScreen @click="toggleFullScreen" />
    </el-icon>
  </div>
</template>

<script lang="ts" setup>
const emits = defineEmits(['update:modelValue'])
const props = defineProps(['modelValue'])

const { modelValue } = toRefs(props)

const toggleFullScreen = () => {
  emits('update:modelValue', !modelValue?.value)
}
</script>

<style lang="scss" scoped>
.com {
  width: 20px;
  height: 20px;
  position: absolute;
  right: 10px;
  top: 5px;
  cursor: pointer;
}
</style>

2.main全局引入样式

.fullscreen-wrap {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
}

3.组件中使用

<template>
	<!-- fullscreen-wrap为全屏内容区域 -->
	<el-card style="min-height: 500px" :class="{ 'fullscreen-wrap': isToggle }">
		<full-screen v-show="holdData.length > 0" v-model="isToggle" style="top: 50px" />
		<el-table
	        :max-height="maxHeight"
	        ...
	      >
      </el-table>
	</el-card>
</template>
<script setup lang="ts">
import fullScreen from '@/components/fullScreen/index.vue'
//table全屏按钮
const isToggle = ref<boolean>(false)
const maxHeight = ref<any>('404px')
//监听控制全局后指定区域的高度&&同理如全屏区域存在echarts等视图则可定义变量重新进行init加载
watch(
  () => isToggle.value,
  (e) => {
    if (e) {
      maxHeight.value = window.innerHeight - 105 + ''
    } else {
      maxHeight.value = '404'
    }
  }
)
</script>
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值