ant-design-vue3-loading-directive
Version:
ant-design-vue loading directive
104 lines (70 loc) β’ 2.24 kB
Markdown
A lightweight ant-design-vue and Vue 3 directive for showing loading overlay on any DOM element.
- Simple and customizable loading mask
- Supports multiple binding formats: boolean, string, object
- Compatible with Vue 3 projects (both Composition API and `<script setup>`)
```bash
npm install ant-design-vue3-loading-directive
```
Or via yarn:
```bash
yarn add ant-design-vue3-loading-directive
```
```js
// main.js or main.ts
import { createApp } from 'vue'
import App from './App.vue'
import LoadingDirective from 'ant-design-vue3-loading-directive'
const app = createApp(App)
app.directive('loading', LoadingDirective)
app.mount('#app')
```
```vue
<template>
<div v-loading="isLoading">Content area</div>
</template>
<script setup>
import { ref } from 'vue'
const isLoading = ref(true)
setTimeout(() => {
isLoading.value = false
}, 2000)
</script>
```
```vue
<div v-loading="'Loading data...'"></div>
```
```vue
<div v-loading="{ spinning: isLoading, tip: 'Fetching data...', size: 'large' }"></div>
```
| Format | Description |
|--------|-------------|
| `boolean` | `true` shows loading, `false` hides it |
| `string` | Sets the loading tip text (`v-loading="'Custom Tip'"`) |
| `object` | Full control: `{ spinning: true, tip: 'Custom', size: 'small' \| 'default' \| 'large' }` |
| Property | Type | Default | Description |
|---------|------|---------|-------------|
| `spinning` | Boolean | `true` | Whether to show loading |
| `tip` | String | `'ε θ½½δΈ...'` | Custom tip text |
| [size](file://d:\project\@ant-design-vue3 v-loading\loading\index.js#L647-L649) | String | `'small'` | Size of the spinner (`small`, `default`, `large`) |
To build the package yourself:
```bash
git clone https://github.com/yourname/v-loading-directive.git
cd v-loading-directive
npm install
npm run build
```
The built files will be in the `dist/` folder.
MIT License