vue二次封装ant-design-vue中的Modal弹窗组件,实现拖拽,全屏两种功能,原有参数属性不变
<template>
<a-modal
:width="width"
:title="title"
:visible="visible"
:confirmLoading="confirmLoading"
:footer="null"
:destroyOnClose="true"
@cancel="handleCancel"
:draggable="true"
:maskClosable="false"
>
<!-- 自定义内容 -->
<slot></slot>
<!-- 工具栏 -->
<div class="modal-toolbar">
<a-icon type="fullscreen" @click="handleFullScreen" />
<a-icon type="close" @click="handleCancel" />
</div>
</a-modal>
</template>
<script>
import Vue from 'vue';
import { Modal as AntModal, Icon as AntIcon } from 'ant-design-vue';
Vue.use(AntModal);
Vue.use(AntIcon);
export default {
name: 'DraggableModal',
props: {
width: {
type: Number,
default: 520
},
title: {
type: String,
default: ''
},
visible: {
type: Boolean,
default: false
},
confirmLoading: {
type: Boolean,
default: false
}
},
methods: {
handleCancel() {
this.$emit('update:visible', false);
},
handleFullScreen() {
// 实现全屏逻辑
}
}
};
</script>
<style scoped>
.modal-toolbar {
position: absolute;
right: 10px;
top: 10px;
z-index: 10;
}
.modal-toolbar .ant-icon {
cursor: pointer;
margin-left: 10px;
}
</style>
这个代码示例展示了如何创建一个可以拖拽和全屏的Ant Design Vue模态框组件。组件接受标准的a-modal
属性,并添加了draggable
和handleFullScreen
方法来实现这两个额外的功能。注意,实现全屏功能需要额外的逻辑来处理样式和位置的变化。
评论已关闭