tip.vue 1.69 KB
<template>
    <transition name="fade">
        <div class="tip" v-if="show">
            {{text}}
            <span class="close" v-if="hasClose" @click="closeTip"></span>
        </div>
    </transition>
</template>

<script>
export default {
    name: 'navTitle',
    props: {
        text: {
            type: String,
            default: ''
        },
        show: {
            type: Boolean,
            default: false
        },
        hasClose: {
            type: Boolean,
            default: false
        }
    },
    watch: {
        show(item) {
            if (item && !this.hasClose) {
                setTimeout(() => {
                    this.$emit('change-tip-status', false);
                }, 1000);
            }
        }
    },
    methods: {
        closeTip() {
            this.$emit('change-tip-status', false);
        }
    }
}
</script>

<style lang="scss" scoped>
.tip {
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 10px 20px;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
    text-align: center;

    .close {
        position: absolute;
        width: 20px;
        height: 20px;
        line-height: 20px;
        background: #666;
        text-align: center;
        right: 5px;
        top: 50%;
        margin-top: -10px;
        border-radius: 50%;
        border: 1px solid #fff;
        cursor: pointer;

        &:after {
            content: "\00D7";
            display: block;
            color: #fff;
            font-size: 16px;
        }
    }
}

.fade-enter-active, .fade-leave-active {
    transition: opacity .2s;
}

.fade-enter, .fade-leave-to {
    opacity: 0;
}
</style>