SOURCE

console 命令行工具 X clear

                    
>
console
let Confirm = Vue.extend({
            template: '#confirm',
            props: {
                text: {
                    type: String,
                    default: '标题内容'
                },
                confirmText: {
                    type: String,
                    default: '确定'
                },
                cancelText: {
                    type: String,
                    default: '取消'
                }

            },
            data() {
                return {
                    showFlag: false
                }
            },
            methods: {
                show() {
                    this.showFlag = true;
                },
                hide() {
                    this.showFlag = false;
                },
                cancel() {
                    this.hide()
                    this.$emit('cancel')
                },
                confirm() {
                    this.hide()
                    this.$emit('confirm')
                }
            }
        })

        let app = new Vue({
            el: '#app',
            components: {
                'Confirm': Confirm
            },
            data() {
                return {
                    text: '确定要删除吗?崽!'
                }
            },
            methods: {
                openConfirm() {
                    this.$refs.confirm.show()
                },
                sure() {
                    console.log('点击了确认')
                }
            }

        })
<div id="app">
        <confirm ref="confirm" :text="text" @confirm="sure"></confirm>
        <button @click="openConfirm">点击打开确认框</button>
    </div>

    <template id="confirm">
        <transition name="confirm-fade">
            <div class="confirm" v-show="showFlag">
                <div class="confirm-wrapper">
                    <div class="confirm-content">
                        <p class="text">{{text}}</p>
                        <div class="operate">
                            <div @click.stop="cancel" class="operate-btn left">
                                {{cancelText}}
                            </div>
                            <div @click.stop="confirm" class="operate-btn ok">
                                {{confirmText}}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
    </template>
.confirm {
            position: fixed;
            left: 0;
            bottom: 0;
            top: 0;
            right: 0;
            z-index: 998;
            background: rgba(0, 0, 0, 0.1)
        }

        .confirm .confirm-wrapper {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 999;
        }

        .confirm .confirm-wrapper .confirm-content {
            width: 270px;
            border-radius: 13px;
            background: #fff;
        }

        .confirm .confirm-wrapper .confirm-content .text {
            padding: 19px 15px;
            line-height: 22px;
            text-align: center;
            color: #000;
        }

        .confirm .confirm-wrapper .confirm-content .operate {
            display: flex;
            align-items: center;
            text-align: center;
        }

        .confirm .confirm-wrapper .confirm-content .operate .operate-btn {
            flex: 1;
            line-height: 22px;
            padding: 10px 0;
            border-top: 1px solid #4fc08d;
        }

        .confirm .confirm-wrapper .confirm-content .operate .left {
            border-right: 1px solid #4fc08d;
            color: #666;
        }
        .confirm .confirm-wrapper .confirm-content .operate .ok {
            color: #4fc08d
        }

        @keyframes confirm-fadein {
            0% {
                opacity: 0;
            }

            100% {
                opacity: 1;
            }
        }

        @keyframes confirm-zoom {
            0% {
                transform: scale(0);
            }

            50% {
                transform: scale(1.1);
            }

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


        

        .confirm-fade-enter-active {
           animation: confirm-fadein 0.5s;
        }



        .confirm-content {
            animation: confirm-zoom 0.3s;
        }