DaiLog组件封装(提示框)

<script setup lang="ts">
import { ref } from 'vue'
const centerDialogVisible = ref(false)
const open = () => { centerDialogVisible.value = true }
const close = () => { centerDialogVisible.value = false }
const a =() =>{
    console.log("a");
    
}
// 动态暴露我们的组件属性
const prop = defineProps({
    title: String,
    width: {
        type: String,
        default: "25%",
    },
    destroyOnClose: {
        type: Boolean,
        default: false
    },
    calText:{
        type:String,
        default:"取消"
    },
    comfirmText: {
        type: String,
        default: "提交"
    },
})
const loading = ref(false)
const showloading = () => loading.value = true
const closeloading = () => loading.value = false
// 向外暴露点击事件
const emit = defineEmits(["submit", "empty"])
const submit = () => emit("submit")
const empty = () => emit("empty")
// 向父组件暴露一下方法
defineExpose({
    open,
    close,
    showloading,
    closeloading,
    prop
})
</script>
<template>
    <el-dialog v-model="centerDialogVisible" :title="title" :width="width" center align-center>
            <div class="body">
                <!-- 这是插槽,<slot></slot> 是 HTML 的一个重要特性,也是 Web 组件(Web Components)的一部分。
                            它允许开发者在自定义组件中插入占位符,以便在将来使用时,可以在这些占位符中填充内容。 -->
                <slot></slot>
            </div>
            <template #footer>
                <span>
                    <el-button @click="empty">{{ calText }}</el-button>
                    <el-button type="primary" @click="submit">
                        {{ comfirmText }}
                    </el-button>
                </span>
            </template>
    </el-dialog>
</template>
<style>
.formDrawer {
    @apply ;
}

.DrawerForm {
    width: 100%;
    height: 100%;
    position: relative;
    /* flex-col垂直排布 */
    @apply flex flex-col;
}

.body {
    /* 超出部分是滚动 */
    overflow-y: auto;
    @apply ;
}

/* margin-top:auto就是会自动至于底部,但是很重要的是!父和子组件都要是块级组件 */
.actions {
    height: 50px;
    @apply mt-auto flex items-center;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的示例代码: ```html <template> <div class="dialog-mask" v-show="visible"> <div class="dialog"> <div class="dialog-header">{{ title }}</div> <div class="dialog-body"> <slot></slot> </div> <div class="dialog-footer"> <button class="cancel-btn" @click="handleCancel">取消</button> <button class="confirm-btn" @click="handleConfirm">确认</button> </div> </div> </div> </template> <script> export default { props: { title: { type: String, default: '提示' }, visible: { type: Boolean, default: false } }, methods: { handleCancel() { this.$emit('update:visible', false); this.$emit('cancel'); }, handleConfirm() { this.$emit('update:visible', false); this.$emit('confirm'); } } } </script> <style> .dialog-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); z-index: 999; } .dialog { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; background: #fff; border-radius: 4px; } .dialog-header { padding: 10px 20px; font-weight: bold; font-size: 16px; border-bottom: 1px solid #eee; } .dialog-body { padding: 20px; } .dialog-footer { padding: 10px 20px; text-align: right; } .cancel-btn { margin-right: 10px; } .confirm-btn { background: #1890ff; color: #fff; border: none; border-radius: 4px; padding: 6px 12px; cursor: pointer; } </style> ``` 使用示例: ```html <template> <div> <button @click="visible = true">打开对话框</button> <el-dialog :visible.sync="visible" @confirm="handleConfirm" @cancel="handleCancel"> <p>这是一个提示对话框</p> </el-dialog> </div> </template> <script> import ElDialog from './ElDialog.vue' export default { components: { ElDialog }, data() { return { visible: false } }, methods: { handleConfirm() { console.log('点击了确认按钮') }, handleCancel() { console.log('点击了取消按钮') } } } </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值