先看看效果
image.png创建global.ts,记录加载加载状态
import { ref } from "vue";
// 加载状态处理
const loadingStatus = ref(false);
export function setLoading(statu: boolean) {
loadingStatus.value = statu;
}
export function getLoading(): boolean {
return loadingStatus.value;
}
创建
<template>
<div class="loading" v-if="getLoading()">
<div class="loadEffect">
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
</div>
</div>
</template>
<script lang="ts">
import { setLoading, getLoading } from "./global";
export default {
name: "loading",
setup() {
return {
getLoading,
};
},
mounted() {
setTimeout(() => {
if (getLoading()) {
setLoading(false);
}
}, 10000);
},
};
</script>
<style scoped lang="scss">
.loading {
z-index: 2;
width: 100%;
position: absolute;
left: 0;
bottom: 0;
right: 0;
top: 0;
background: #e6e6e1;
color: #fff;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
font-size: 14px;
font-family: HuaweiSans-Regular;
.loadEffect {
width: 50px;
height: 50px;
position: relative;
}
@keyframes loaded {
100% {
opacity: 0.2;
}
0% {
opacity: 1;
}
}
.circle {
display: flex;
width: 8px;
height: 8px;
border-radius: 50%;
background: #ffffff;
position: absolute;
animation: loaded 1.1s ease infinite;
}
.circle:nth-child(1) {
left: 0;
top: 50%;
margin-top: -4px;
animation-delay: 0.13s;
}
.circle:nth-child(2) {
left: 7px;
top: 7px;
animation-delay: 0.26s;
}
.circle:nth-child(3) {
left: 50%;
top: 0;
margin-left: -4px;
animation-delay: 0.39s;
}
.circle:nth-child(4) {
top: 7px;
right: 7px;
animation-delay: 0.52s;
}
.circle:nth-child(5) {
right: 0;
top: 50%;
margin-top: -4px;
animation-delay: 0.65s;
}
.circle:nth-child(6) {
right: 7px;
bottom: 7px;
animation-delay: 0.78s;
}
.circle:nth-child(7) {
bottom: 0;
left: 50%;
margin-left: -4px;
animation-delay: 0.91s;
}
.circle:nth-child(8) {
bottom: 7px;
left: 7px;
animation-delay: 1.04s;
}
}
</style>
点赞加关注,永远不迷路
网友评论