当前位置: 首页> 财经> 产业 > Vue3----扩展 element Plug card

Vue3----扩展 element Plug card

时间:2025/8/23 12:31:39来源:https://blog.csdn.net/damys/article/details/140776580 浏览次数:0次

扩展 element Plug card

增加全屏,折叠操作项

核心代码

<template><div class="cc-card-component"><el-card v-if="state.isShow" :class="state.class" :bodyStyle="bodyStyle" :shadow="props.shadow"><template #header v-if="props.title"><slot name="leftIcon"></slot><span>{{ props.title }}</span><div class="component-header-icon"><template v-if="props.showFullScreen"><i v-if="state.isFullscreen" @click="toggleFullscreen" class="iconfont icon--fullscreen-exit"></i><i v-else @click="toggleFullscreen" class="iconfont icon--fullscreen"></i></template><i v-if="props.showClose" @click="handleBeforeClose" class="iconfont icon--close"></i><i v-if="props.showExpand" @click="toggleExpand" class="iconfont icon--arrow-right"></i></div></template><template v-for="(slot, slotName) in $slots" #[slotName]><slot :name="slotName"></slot></template></el-card></div>
</template><script setup lang="ts">
import { reactive } from 'vue'const props = defineProps({shadow: {type: String,default: 'hover', // always | never | hover},title: {type: String,default: '',},showFullScreen: {type: Boolean,default: false,},showExpand: {type: Boolean,default: true,},showClose: {type: Boolean,default: false,},bodyStyle: {type: String,default: '',},
})const state = reactive({isShow: true,isExpand: false,isFullscreen: false,class: '',
})const toggleFullscreen = () => {state.isFullscreen = !state.isFullscreenstate.class = state.isFullscreen ? 'max-fullscreen' : ''
}const toggleExpand = () => {state.isExpand = !state.isExpandstate.class = state.isExpand ? 'card-isExpand' : ''
}const handleBeforeClose = () => {state.isShow = false
}
</script><style lang="scss">
.cc-card-component {.el-card__header {padding: 0 10px;line-height: 40px;}.component-header-icon > i {display: inline-block;}.max-fullscreen {width: 100% !important;height: 100% !important;position: fixed;top: 0;left: 0;bottom: 0;right: 0;z-index: 10;transition: all 0.3s ease 0.1s;}.icon--arrow-right {cursor: pointer;transform: rotate(90deg);transform-origin: center center;transition: all 0.3s ease 0.1s;}.card-isExpand {.icon--arrow-right {transform: rotate(-90deg);}.el-card__body {display: none;}}
}.cc-card-component.left-card .el-card {overflow-y: auto;height: calc(100vh - 120px);
}
</style>

一般使用

<cc-card title="设置验证码">
...
</cc-card>

效果图
在这里插入图片描述

关键字:Vue3----扩展 element Plug card

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: