vue之loading组件

vue之loading组件

转载于:链接: link.
转载于:链接: link.
在这里插入图片描述
在这里插入图片描述

组件1

//loading效果组件

<template>
<div class="loadEffect" :style="{marginTop: marginTop? marginTop : '50%'}">
    <span class="ld-span"></span>
    <span class="ld-span"></span>
    <span class="ld-span"></span>
    <span class="ld-span"></span>
    <span class="ld-span"></span>
    <span class="ld-span"></span>
    <span class="ld-span"></span>
    <span class="ld-span"></span>
</div>
</template>

<script>
export default {
  name: 'Loading',
  props: ["marginTop"]
}
</script>

<style scoped>
.loadEffect{
    width: 100px;
    height: 100px;
    position: relative;
    margin: 0 auto;
    position: relative;
    top:-50px;
    margin-top:50%;
    transform: scale(.5)
}
.loadEffect .ld-span{
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #67e7d5;
    position: absolute;
    -webkit-animation: load 1.04s ease infinite;
}
@-webkit-keyframes load{
    0%{
    -webkit-transform: scale(1.2);
    opacity: 1;
    }
    100%{
    -webkit-transform: scale(.3);
    opacity: 0.5;
    }
}
.loadEffect .ld-span:nth-child(1){
    left: 0;
    top: 50%;
    margin-top:-10px;
    -webkit-animation-delay:0.13s;
}
.loadEffect .ld-span:nth-child(2){
    left: 14px;
    top: 14px;
    -webkit-animation-delay:0.26s;
}
.loadEffect .ld-span:nth-child(3){
    left: 50%;
    top: 0;
    margin-left: -10px;
    -webkit-animation-delay:0.39s;
}
.loadEffect .ld-span:nth-child(4){
    top: 14px;
    right:14px;
    -webkit-animation-delay:0.52s;
}
.loadEffect .ld-span:nth-child(5){
    right: 0;
    top: 50%;
    margin-top:-10px;
    -webkit-animation-delay:0.65s;
}
.loadEffect .ld-span:nth-child(6){
    right: 14px;
    bottom:14px;
    -webkit-animation-delay:0.78s;
}
.loadEffect .ld-span:nth-child(7){
    bottom: 0;
    left: 50%;
    margin-left: -10px;
    -webkit-animation-delay:0.91s;
}
.loadEffect .ld-span:nth-child(8){
    bottom: 14px;
    left: 14px;
    -webkit-animation-delay:1.04s;
}
</style>

组件2

<template>
    <div class="loader"></div>
</template>

<script>
export default {
    name: 'Loading'
}
</script>

<style lang="scss" scoped>
$colors:
  hsla(337, 84, 48, 0.75)
  hsla(160, 50, 48, 0.75)
  hsla(190, 61, 65, 0.75)
  hsla( 41, 82, 52, 0.75);
$size: 2.5em;
$thickness: 0.5em;

// Calculated variables.
$lat: ($size - $thickness) / 2;
$offset: $lat - $thickness;

.loader {
  position: relative;
  width: $size;
  height: $size;
  transform: rotate(165deg);
  
  &:before,
  &:after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    display: block;
    width: $thickness;
    height: $thickness;
    border-radius: $thickness / 2;
    transform: translate(-50%, -50%);
  }
  
  &:before {
    animation: before 2s infinite;
  }
  
  &:after {
    animation: after 2s infinite;
  }
}

@keyframes before {
  0% {
    width: $thickness;
    box-shadow:
      $lat (-$offset) nth($colors, 1),
      (-$lat) $offset nth($colors, 3);
  }
  35% {
    width: $size;
    box-shadow:
      0 (-$offset) nth($colors, 1),
      0   $offset  nth($colors, 3);
  }
  70% {
    width: $thickness;
    box-shadow:
      (-$lat) (-$offset) nth($colors, 1),
      $lat $offset nth($colors, 3);
  }
  100% {
    box-shadow:
      $lat (-$offset) nth($colors, 1),
      (-$lat) $offset nth($colors, 3);
  }
}

@keyframes after {
  0% {
    height: $thickness;
    box-shadow:
      $offset $lat nth($colors, 2),
      (-$offset) (-$lat) nth($colors, 4);
  }
  35% {
    height: $size;
    box-shadow:
        $offset  0 nth($colors, 2),
      (-$offset) 0 nth($colors, 4);
  }
  70% {
    height: $thickness;
    box-shadow:
      $offset (-$lat) nth($colors, 2),
      (-$offset) $lat nth($colors, 4);
  }
  100% {
    box-shadow:
      $offset $lat nth($colors, 2),
      (-$offset) (-$lat) nth($colors, 4);
  }
}


html,
body {
  height: 100%;
}

.loader {
  position: absolute;
  top: calc(50% - #{$size / 2});
  left: calc(50% - #{$size / 2});
}

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中,可以通过在异步加载组件时添加loading状态来提供用户反馈。以下是一种常用的方式: 1. 创建一个Loading组件,用于显示加载状态的UI。例如,可以创建一个`Loading.vue`组件: ```vue <template> <div class="loading"> <span>Loading...</span> </div> </template> <script> export default { name: 'Loading', }; </script> <style scoped> .loading { display: flex; justify-content: center; align-items: center; height: 100px; } </style> ``` 2. 在异步加载组件时,可以添加一个loading标志位来表示加载状态。例如,在使用`import()`函数动态导入组件时: ```javascript data() { return { isLoading: true, // 初始加载状态为true component: null, // 初始化组件为null }; }, mounted() { import('./AsyncComponent.vue') .then((component) => { this.component = component.default; // 导入组件 this.isLoading = false; // 加载完成,loading状态为false }) .catch((error) => { console.error('Failed to load component:', error); this.isLoading = false; // 加载失败,loading状态为false }); }, ``` 3. 在模板中根据loading状态显示相应的内容。例如: ```vue <template> <div> <!-- 根据loading状态显示不同内容 --> <div v-if="isLoading"> <Loading /> </div> <div v-else> <component :is="component" /> </div> </div> </template> <script> import Loading from './Loading.vue'; export default { components: { Loading, }, // ... }; </script> ``` 在上述代码中,根据`isLoading`的值显示不同内容,当`isLoading`为`true`时,显示`Loading`组件;当`isLoading`为`false`时,显示异步加载的组件。 通过以上方式,您可以在异步加载组件时提供加载状态的反馈。希望能对您有所帮助!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值