Skip to content

Loading

Service and directive entry for displaying loading masks. It is built on top of YhSpin and is primarily used through YhLoading.service(...) and the v-yh-loading directive.

Relationship between Loading and Spin

Loading is the directive and service layer built on top of Spin, while Spin is the lower-level visual loading component.

  • Spin is responsible for rendering icons, tips, and loading animation layouts.
  • Loading adds service mounting, fullscreen masking, scroll locking, directive support, and temporary host management.

Usage

Regional Loading (Directive Version)

Use the v-yh-loading directive to cover a host element with a loading mask.

This is container content
Basic Usage

Advanced Directive Usage

Directive modifiers such as .fullscreen, .lock, and .glass, together with the yh-loading-* attributes, provide richer loading interactions.

Directive Fullscreen and Locking
This is a dark container background
Directive Extension Attributes

System Core Dashboard

Rendering real-time data stream through acrylic glass filter...

Directive Flagship Glass Mode

Asset Management Queue

Dot loading mode for lightweight container feedback

Directive Dot Mode

Deep Customization

Applying special filter via my-custom-mask class...

Directive Custom Class Name

Use YhLoading.service inside setup to open and close loading masks imperatively.

Composition API Call

Options API

After installing the plugin, the service is also available through $loading.

Options API Call

Use in Nuxt

YhLoading works in Nuxt 3/4 after registering @yh-ui/nuxt. Call the service from client-side interaction handlers or lifecycle hooks, and use the directive directly in templates for container masks.

ts
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@yh-ui/nuxt']
})

Usage in Axios

In real projects, combine Axios interceptors with a small reference counter so the mask only closes after the last concurrent request finishes.

This counter strategy ensures that only the first request opens Loading, and the mask stays visible until the last concurrent request completes.

Network Request Interception Example

Flagship Loading Styles

Inspired by the motion styles of loading.io.

Premium Animations

Custom Color Schemes

Single colors, gradient color arrays, and CSS-variable based colors are all supported.

Multi-color Animations

Fully Custom Expansion (VNode or Component)

Pass a custom spinner to replace the built-in loading renderer with your own VNode or component.

Custom VNode Demo

Application Context

YhLoading.service accepts the current app context as the second argument so content rendered inside the service can inherit global components and plugins.

TIP

If YhLoading is installed globally, the service already runs with the application context created by the plugin.

By passing `appContext`, components mounted inside Loading can access globally registered plugins such as Pinia or Vue Router.

Application Context Injection

API

Props

This entry does not expose configuration through component props. Use YhLoading.service(...) or v-yh-loading instead.

Events

This entry does not expose component events.

Slots

This entry is not used as a regular template component and does not expose standalone component slots.

Expose

This entry does not expose component-instance defineExpose members. Service capabilities are returned from YhLoading.service(...).

Loading Options

PropertyDescriptionTypeDefault
targetMount target element or selectorstring | HTMLElementdocument.body
bodyWhether to append to the body containerbooleanfalse
fullscreenWhether to render as a fullscreen fixed maskbooleantrue
lockWhether to lock scrolling on the targetbooleanfalse
textLoading tip textstringundefined
spinnerCustom icon, component, or VNodestring | Component | VNodeundefined
backgroundCustom mask background colorstringundefined
customClassExtra class name applied to the maskstringundefined
glassWhether to enable the glass-style maskbooleanfalse
colorSpinner color, gradient colors, or color token mapstring | string[] | Record<string, string>undefined
dotWhether to use the dot loading stylebooleanfalse
spinnerTypeBuilt-in loading animation typeLoadingSpinnerType'circle'
themeOverridesComponent-level theme variable overridesComponentThemeVarsundefined

Directive Attributes

NameDescriptionType
yh-loading-textLoading tip textstring
yh-loading-backgroundMask background colorstring
yh-loading-custom-classExtra custom class namestring
yh-loading-glassWhether to enable glass modeboolean
yh-loading-dotWhether to enable dot modeboolean
yh-loading-colorSpinner colorstring
yh-loading-typeBuilt-in spinner typeLoadingSpinnerType

Directive Modifiers

NameDescription
.fullscreenEquivalent to fullscreen: true
.lockEquivalent to lock: true
.glassEquivalent to glass: true

Loading Instance

PropertyDescriptionType
closeClose and destroy the mask() => void
visibleCurrent visible state (readonly)boolean

Theme Variables

VariableDescriptionDefault
--yh-loading-z-indexLoading mask z-index2000

Type Exports

NameDescription
YhLoadingOptionsService options type for YhLoading.service(...)
YhLoadingInstanceReturned loading instance type
vYhLoadingNamed directive export for v-yh-loading

Released under the MIT License.