Vue 封装一个提示窗组件

为了方便有需要弹窗确认的交互,可传入回调方法,标题,内容。可以把组件引入到公共头里,使用中央数据总线bug进行调用。

template层

<template>
  <div class="notarize-window" :class="{hide: hide}" @click="hide = true">
        <div class="notarize-body" @click.stop>
            <div class="header" v-if="config.title">{{ config.title }}</div>
            <div class="content">{{ config.content }}</div>
            <div class="notarize-button-box">
                <div class="list" @click.stop="hide = true">取消</div>
                <div class="list" @click.stop="submit">确定</div>
            </div>
        </div>
  </div>
</template>

script层 通过ref调用此组件的show方法 需要传入一个content为必传项 如需用到点击确认的回调要传进来一个 success 函数;用作callback回调

<script>
export default {
    data() {
        return {
            hide: true,
            success: null,
            config: {
                title: '',
                content: ''
            }
        }
    },
    methods: {
        submit() {
            this.hide = true;
            this.success && this.success()
        },
        /**
         * @param {*} params 
         * title 可选项
         * content 必选项
         * success 可选性(如需用到回调)
         */
        show(params = {}) {
            if(!params.content) return console.error('未传入提示内容')
            this.hide = false;
            this.config.title = params.title;
            this.config.content = params.content;
            this.success = params.success || null;
        }
    }
}
</script>

style层

<style scoped>
.notarize-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 9;
    text-align: center;
}
.notarize-window.hide {
    display: block;
}
.notarize-body {
    width: 480px;
    padding-bottom: 30px;
    border-radius: 10px;
    display: inline-block;
    background-color: #fff;
    animation: EDIT_WORK_SHOW .3s forwards;
}


.notarize-button-box {
    text-align: right;
    margin-top: 30px;
    padding: 0 50px;
}
.notarize-body>.header {
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    padding: 0 30px;
    box-sizing: border-box;
    color: #00C479;
    background-color: #EAFAF6;
    border-radius: 10px 10px 0 0;
}
.notarize-body .content {
    padding: 0 40px;
    margin-top: 30px;
    text-align: left;
    color: #8b8e9d;
    font-size: 16px;
    line-height: 24px;
}
.notarize-button-box .list {
    display: inline-block;
    width: 80px;
    height: 30px;
    line-height: 30px;
    border-radius: 6px;
    background-color: #00C479;
    color: #fff;
    text-align: center;
    cursor: pointer;
}
.notarize-button-box .list:nth-child(1) {
    margin-right: 20px;
}
@keyframes EDIT_WORK_SHOW {
    0% {
        opacity: 0;
        transform: translateY(-100px);
    }
    
    100% {
        opacity: 1;
        transform: translateY(150px);
    }
}
</style>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值