Skip to content

Loading

A spinner for displaying loading state of a page or a section.

When To Use

When part of the page is waiting for asynchronous data or during a rendering process, an appropriate loading animation can effectively alleviate users' inquietude.

Examples

Basic Usage

vue
<template>
  <a-spin />
</template>

Size

vue
<template>
  <div>
    <a-spin size="small" />
    <a-spin />
    <a-spin size="large" />
  </div>
</template>

Container

vue
<template>
  <div>
    <a-spin :spinning="spinning">
      <a-alert
        message="Alert message title"
        description="Further details about the context of this alert."
        type="info"
      />
    </a-spin>
    <div style="margin-top: 20px">
      Loading state:
      <a-switch v-model:checked="spinning" />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const spinning = ref(false)
</script>

Custom spinning indicator

vue
<template>
  <div>
    <a-spin :indicator="indicator" />
    <br />
    <a-spin :spinning="spinning" :indicator="indicator">
      <a-alert
        message="Alert message title"
        description="Further details about the context of this alert."
        type="info"
      />
    </a-spin>
    <div style="margin-top: 20px">
      Loading state:
      <a-switch v-model:checked="spinning" />
    </div>
  </div>
</template>

<script setup>
import { ref, h } from 'vue'
import { LoadingOutlined } from '@ant-design/icons-vue'

const indicator = h(LoadingOutlined, {
  style: {
    fontSize: '24px',
  },
  spin: true,
})

const spinning = ref(false)
</script>

Custom description

vue
<template>
  <div>
    <a-spin tip="Loading...">
      <a-alert
        message="Alert message title"
        description="Further details about the context of this alert."
        type="info"
      />
    </a-spin>
  </div>
</template>

Delaying

vue
<template>
  <div>
    <a-spin :spinning="spinning" :delay="500">
      <a-alert
        message="Alert message title"
        description="Further details about the context of this alert."
        type="info"
      />
    </a-spin>
    <div style="margin-top: 20px">
      Loading state:
      <a-switch v-model:checked="spinning" />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const spinning = ref(false)
</script>

Embedded mode

vue
<template>
  <div class="example">
    <a-spin :spinning="spinning1">
      <div class="spin-content">
        You can click 'Switch' to show loading state.
      </div>
    </a-spin>
    Loading state:
    <a-switch v-model:checked="spinning1" />
  </div>
</template>

<script setup>
import { ref } from 'vue'

const spinning1 = ref(false)
</script>

<style scoped>
.example {
  text-align: center;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
  margin-bottom: 20px;
  padding: 30px 50px;
  margin: 20px 0;
}

.spin-content {
  border: 1px solid #91d5ff;
  background-color: #e6f7ff;
  padding: 30px;
}
</style>

API

Spin

PropertyDescriptionTypeDefaultVersion
delaySpecifies a delay in milliseconds for loading state (prevent flush)number (milliseconds)-
indicatorVue node of the spinning indicatorvNode | slot-
sizeSize of Spin, options: small, default and largestringdefault
spinningWhether Spin is spinningbooleantrue
tipCustomize description content when Spin has childrenstring-
wrapperClassNameThe className of wrapper when Spin has childrenstring-

Static Method

  • Spin.setDefaultIndicator(indicator) (>=4.0.0)

You can define default spin element globally.

jsx
import { h } from 'vue';
import { Spin } from 'ant-design-vue';
import { LoadingOutlined } from '@ant-design/icons-vue';

const indicator = h(LoadingOutlined, {
  style: {
    fontSize: '24px',
  },
  spin: true,
});

Spin.setDefaultIndicator({
  indicator,
});

Released under the MIT License.