Vue自定义模态对话框弹窗

 更新时间:2022年07月05日 11:46:29   作者:mossbaoo  
这篇文章主要为大家详细介绍了Vue自定义模态对话框弹窗,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Vue自定义模态对话框弹窗的具体代码,供大家参考,具体内容如下

模态对话框弹窗效果:

父组件(应用页面)主要代码:

<template>
    <view class="app-container">
        <modal-dialog showText="确定要取消收藏吗?" :isShowDialog="isDialog" @cancel="isDialog = false" @confirm="confirmDelete"></modal-dialog>
    </view>
</template>
 
<script>
    import modalDialog from '@/components/modalDialog.vue';
    
    export default {
        components:{
            modalDialog
        },
        data() {
            return {
                isDialog: false,
            }
        },
        methods: {
            // 业务代码......
            this.isDialog = false;
        }
    }
</script>

子组件(自定义组件)代码:

<template>
    <view>
        <view class="global-mask" v-show="isShowDialog"></view>
        <view class="global-dialog" v-show="isShowDialog" style="top: 45%;">
            <view class="title">温馨提示</view>
            <view class="content">
                <view class="text">{{showText}}</view>
            </view>
            <view class="btn">
                <view class="left" @tap="cancel" v-if="isShowCancel">{{cancelText}}</view>
                <view class="right" @tap="confirm" v-if="isShowConfirm">{{confirmText}}</view>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        name: 'modalDialog',
        props: {
            showText: {
                type: String,
                default: '提示内容'
            },
            isShowDialog: {
                type: Boolean,
                default: false
            },
            isShowCancel: {
                type: Boolean,
                default: true
            },
            cancelText: {
                type: String,
                default: '取消'
            },
            isShowConfirm: {
                type: Boolean,
                default: true
            },
            confirmText: {
                type: String,
                default: '确定'
            }
        },
        data() {
            return {
                
            };
        },
        methods: {
            cancel() {
                this.$emit('cancel');
            },
            
            confirm() {
                this.$emit('confirm');
            }
        }
    }
</script>
 
<style lang="scss">
    .global-mask {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 998;
        width: 100%;
        height: 100%;
        background: rgba($color: #000000, $alpha: 0.3);
    }
    .global-dialog {
        position: fixed;
        top: 500rpx;
        left: 60rpx;
        top: 45%;
        z-index: 999;
        width: 630rpx;
        background: #FFFFFF;
        border-radius: 15rpx;
        overflow: hidden;
        .title {
            font-size: 36rpx;
            font-weight: 500;
            text-align: center;
            line-height: 100rpx;
            padding-bottom: 10rpx;
        }
        .content {
            .text {
                font-size: 32rpx;
                text-align: center;
                padding-bottom: 40rpx;
            }
            .form {
                padding: 0 40rpx;
                .item {
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    margin-bottom: 40rpx;
                    input {
                        width: 340rpx;
                        height: 60rpx;
                        border: 1px solid #eaeaea;
                        border-radius: 10rpx;
                        padding: 0 20rpx;
                    }
                }
            }
        }
        .btn {
            border-top: 1px solid #eaeaea;
            display: flex;
            &> view {
                flex: 1;
                text-align: center;
                line-height: 100rpx;
                font-size: 32rpx;
                &.left {
                    color: #666666;
                }
                &.right {
                    color: #FFFFFF;
                    background: #FF3F42;
                }
            }
        }
    }
</style>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

相关文章

  • 一文带你了解Vue中单文件组件的使用

    一文带你了解Vue中单文件组件的使用

    在web开发中,组件化开发已成为一种趋势,Vue提供了一种高效的方式来创建和管理这些组件—单文件组件,下面我们就来看看它的具体应用吧
    2024-03-03
  • vue-admin-box第一步npm install时报错的处理

    vue-admin-box第一步npm install时报错的处理

    这篇文章主要介绍了vue-admin-box第一步npm install时报错的处理方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-10-10
  • VeeValidate 的使用场景以及配置详解

    VeeValidate 的使用场景以及配置详解

    这篇文章主要介绍了VeeValidate 的使用场景以及配置详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-01-01
  • vue-cli3单页构建大型项目方案

    vue-cli3单页构建大型项目方案

    这篇文章主要介绍了vue-cli3单页构建大型项目方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-04-04
  • Vue2 中的数据劫持简写示例

    Vue2 中的数据劫持简写示例

    这篇文章主要为大家介绍了Vue2 中的数据劫持简写示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02
  • vue中的vue-router query方式和params方式详解

    vue中的vue-router query方式和params方式详解

    这篇文章主要介绍了vue中的vue-router query方式和params方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-08-08
  • Spring boot 和Vue开发中CORS跨域问题解决

    Spring boot 和Vue开发中CORS跨域问题解决

    这篇文章主要介绍了Spring boot 和Vue开发中CORS跨域问题解决,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-09-09
  • vuejs中父子组件之间通信方法实例详解

    vuejs中父子组件之间通信方法实例详解

    这篇文章主要介绍了vuejs中父子组件之间通信方法,结合实例形式详细分析了vue.js父组件向子组件传递消息以及子组件向父组件传递消息具体操作实现技巧,需要的朋友可以参考下
    2020-01-01
  • 详解vue中使用axios对同一个接口连续请求导致返回数据混乱的问题

    详解vue中使用axios对同一个接口连续请求导致返回数据混乱的问题

    这篇文章主要介绍了详解vue中使用axios对同一个接口连续请求导致返回数据混乱的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • vue动态路由配置及路由传参的方式

    vue动态路由配置及路由传参的方式

    这篇文章主要介绍了vue动态路由配置,vue路由传参的方式,文中给大家提到了router-link这个组件的相关知识,需要的朋友可以参考下
    2018-05-05

最新评论