Vue3 之dialog弹框简单制作

一、效果图

二、代码

mydialog.vue

复制代码
<template>
    <div class="vux-x-dialog">
        <transition :name="maskTransition">
            <div class="weui-mask" @click.self="hide" v-show="show" :style="maskStyle">
                <transition :name="dialogTransition">
                    <div :class="dialogClass" v-show="show" :style="dialogStyle">
                        <slot></slot>
                    </div>
                </transition>
            </div>
        </transition>
    </div>
</template>

<script>
    export default {
        name: 'x-dialog',
        model: {
            prop: 'show',
            event: 'change'
        },
        props: {
            show: {
                type: Boolean,
                default: false
            },
            maskTransition: {
                type: String,
                default: 'vux-mask'
            },
            maskZIndex: [String, Number],
            dialogTransition: {
                type: String,
                default: 'vux-dialog'
            },
            dialogClass: {
                type: String,
                default: 'weui-dialog'
            },
            hideOnBlur: Boolean,
            dialogStyle: Object
        },
        computed: {
            maskStyle() {
                if (typeof this.maskZIndex !== 'undefined') {
                    return {
                        zIndex: this.maskZIndex
                    }
                }
            }
        },
        mounted() {

        },
        watch: {
            show(val) {
                this.$emit('update:show', val)
                this.$emit(val ? 'on-show' : 'on-hide')
            }
        },
        methods: {
            hide() {
                if (this.hideOnBlur) {
                    this.$emit('update:show', false)
                }
            }
        },
        data() {
            return {

            }
        }
    }
</script>

<style scoped>
    .weui-dialog {
        position: fixed;
        display: table;
        z-index: 5000;
        width: 80%;
        max-width: 300px;
        margin: auto;
        background-color: #fff;
        text-align: center;
        border-radius: 3px;
        overflow: hidden;
    }

    .weui-mask .weui-dialog {
        position: relative;
    }

    .weui-mask {
        position: fixed;
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 1000;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
        background: rgba(0, 0, 0, .6);
    }

    .vux-x-dialog .weui-mask {
        background: rgba(0, 0, 0, .5);
        position: fixed;
        z-index: 1000;
    }

    .weui-mask_transparent {
        position: fixed;
        z-index: 1000;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
    }

    .vux-fade-enter-active,
    .vux-fade-leave-active {
        opacity: 1;
        transition: opacity linear 0.2s;
    }

    .vux-fade-enter,
    .vux-fade-leave-to {
        opacity: 0;
    }

    .vux-dialog-enter-active {
        animation: vux-dialog-in .5s;
    }

    .vux-dialog-leave-active {
        animation: vux-dialog-out .3s;
    }

    @keyframes vux-dialog-in {
        0% {
            transform: scale(1.185);
            opacity: 0;
        }

        100% {
            transform: scale(1);
            opacity: 1;
        }
    }

    @keyframes vux-dialog-out {
        0% {
            transform: scale(1);
            opacity: 1;
        }

        100% {
            transform: scale(0.85);
            opacity: 0;
        }
    }

    .vux-mask-enter,
    .vux-mask-leave-active {
        opacity: 0;
    }

    .vux-mask-leave-active,
    .vux-mask-enter-active {
        transition: opacity 300ms;
    }
</style>

三、使用

复制代码
import XDialog from '@/components/MyDialog.vue';

const isshow = ref(false)
const handleShowUpdate = (val) => {
    isshow.value = val
}
const dShow = () => {
    alert('show')
}
const dHide = () => {
    alert('hide')
}

<x-dialog :show="isshow" :dialogStyle="{width: '27rem', maxWidth: '27rem', borderRadius: '8px'}" :hideOnBlur="true" @update:show="handleShowUpdate" @on-show="dShow" @on-hide="dHide">
    123
</x-dialog>
相关推荐
xiaoqi92239 分钟前
React Native鸿蒙跨平台如何进行狗狗领养中心,实现基于唯一标识的事件透传方式是移动端列表开发的通用规范
javascript·react native·react.js·ecmascript·harmonyos
jin1233221 小时前
React Native鸿蒙跨平台剧本杀组队消息与快捷入口组件,包含消息列表展示、快捷入口管理、快捷操作触发和消息详情预览四大核心功能
javascript·react native·react.js·ecmascript·harmonyos
烬头88213 小时前
React Native鸿蒙跨平台实现二维码联系人APP(QRCodeContactApp)
javascript·react native·react.js·ecmascript·harmonyos
pas1363 小时前
40-mini-vue 实现三种联合类型
前端·javascript·vue.js
摇滚侠3 小时前
2 小时快速入门 ES6 基础视频教程
前端·ecmascript·es6
2601_949833393 小时前
flutter_for_openharmony口腔护理app实战+预约管理实现
android·javascript·flutter
珑墨3 小时前
【Turbo】使用介绍
前端
军军君014 小时前
Three.js基础功能学习十三:太阳系实例上
前端·javascript·vue.js·学习·3d·前端框架·three
xiaoqi9225 小时前
React Native鸿蒙跨平台如何实现分类页面组件通过searchQuery状态变量管理搜索输入,实现了分类的实时过滤功能
javascript·react native·react.js·ecmascript·harmonyos
打小就很皮...5 小时前
Tesseract.js OCR 中文识别
前端·react.js·ocr