返回

用 Element UI 实现加载动画

前端

前言

Element UI 是一个强大的前端 UI 框架,它提供了许多现成的组件,可以帮助我们快速构建高质量的 web 应用程序。Element UI 的 loading 组件是一个常见的组件,它可以在页面加载时显示一个加载动画,以提示用户正在等待。

实现步骤

1. 安装 Element UI

首先,我们需要安装 Element UI。我们可以通过 npm 或 yarn 来安装。

npm install element-ui

yarn add element-ui

2. 导入 Element UI

在我们的项目中,我们需要导入 Element UI。

import Vue from 'vue'
import ElementUI from 'element-ui'

Vue.use(ElementUI)

3. 创建一个加载动画组件

接下来,我们需要创建一个加载动画组件。

<template>
  <div class="loading">
    <div class="loading-circle">
      <div class="loading-circle-inner"></div>
    </div>
  </div>
</template>

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

<style>
.loading {
  width: 100px;
  height: 100px;
  position: relative;
}

.loading-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: absolute;
  animation: loading-circle 1s infinite;
}

.loading-circle-inner {
  width: 50%;
  height: 50%;
  border-radius: 50%;
  position: absolute;
  top: 25%;
  left: 25%;
  background-color: blue;
  animation: loading-circle-inner 1s infinite;
}

@keyframes loading-circle {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes loading-circle-inner {
  0% {
    transform: scale(0);
  }

  50% {
    transform: scale(1);
  }

  100% {
    transform: scale(0);
  }
}
</style>

4. 使用加载动画组件

现在,我们可以使用加载动画组件了。

<template>
  <div>
    <loading />
  </div>
</template>

<script>
import Loading from './Loading.vue'

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

5. 结果

现在,我们已经成功地实现了一个 Element UI 加载动画。