Vue动态Loading加载中纯Css实现

如图所示:

图片[1]-Vue动态Loading加载中纯Css实现-小栋博客

等待数据返回等等...

开箱即用比UI好用

<template>
    <div>
        <button @click="showLoading">显示加载中消息</button>
        <div v-if="loading" class="loading">
            <div class="loading-message">
                <div class="loading-spinner"></div>
                <div class="loading-text">加载中...</div>
            </div>
        </div>
    </div>
</template>

<script>
import { ref } from 'vue'

export default {
    setup() {
        const loading = ref(false)

        function showLoading() {
            loading.value = true
        }

        function hideLoading() {
            loading.value = false
        }

        return {
            loading,
            showLoading,
            hideLoading
        }
    }
}
</script>

<style>
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-message {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    padding: 20px;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #fff;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
    margin-right: 10px;
}

.loading-text {
    color: #fff;
    font-size: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
</style>

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容