Vue-Wait is a Vue plugin designed for comprehensive global loading state management within Vue applications, optionally integrating with Vuex. It simplifies the handling of multiple concurrent loading processes, preventing UI conflicts and providing clear visual feedback to users. The current stable version, 1.5.3, includes important updates like Vue 3 support, released in v1.5.0, demonstrating ongoing maintenance and adaptability to the evolving Vue ecosystem. The library distinguishes itself by offering both a declarative component (`<v-wait>`) and a directive (`v-wait`) for displaying loading indicators, alongside a programmatic API (`$wait.start()`, `$wait.end()`) for granular control over individual loading states. Additionally, it provides features for progress indication and configurable Vuex integration, making it a flexible solution for various application sizes and complexities. Its core idea relies on an array-based system to track active wait states, making it intuitive to manage.
npm install vue-waitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the setup of Vue-Wait in a Vue 3 application, showing how to instantiate and register the plugin globally. It also includes commented-out example Vue component code to illustrate how to use the `<v-wait>` component and the `$wait` service to manage and display loading states for an asynchronous operation.
For Vue 3, import `createVueWait` as a named export and use `app.use(createVueWait())`. For Vue 2, import `VueWait` as a default export and instantiate it within the Vue instance options: `new Vue({ wait: new VueWait() })`.Replace all calls to `this.$wait.isWaiting('processName')` with `this.$wait.is('processName')`. An alias `waiting(waiter)` was added in v1.3.0.Initialize VueWait with `{ useVuex: true }`: `new VueWait({ useVuex: true })` or `createVueWait({ useVuex: true })`.Add a declaration file (e.g., `vue-wait.d.ts`) to augment the Vue instance type:
```typescript
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$wait: import('vue-wait').VueWaitInstance;
}
}
// For Vue 2 (if not using @vue/runtime-core):
declare module 'vue/types/vue' {
interface Vue {
$wait: import('vue-wait').VueWaitInstance;
}
}
```For Vue 2, ensure `new Vue({ ..., wait: new VueWait(), ... })` is present. For Vue 3, ensure `app.use(createVueWait())` is called after `createApp()`.Ensure `registerComponent: true` (which is the default) in the VueWait options. If `componentName` was changed, update your template accordingly (e.g., `<my-loader>`).