vue-wait
Multiple Process Loader Management for Vue and (optionally) Vuex.
This project formerly known as vuex-loading.
vue-wait helps to manage multiple loading states on the page without any conflict. It's based on a very simple idea that manages an array (or Vuex store optionally) with multiple loading states. The built-in loader component listens its registered loader and immediately become loading state.
? Requirements
- Vue.js (v2.0.0+)
? Power Supplies
- Vuex, optionally (v2.0.0+)
? Installation
? Usage
Then you should register wait
property (VueWait
instance) to the Vue instance:
♻️ Usage with Vuex
Simply set useVuex
parameter to true
and optionally override
vuexModuleName
Then you should register VueWait
module:
Now VueWait
will use Vuex
store for data management which can be traced in Vue DevTools > Vuex
♻️ Usage with Nuxt.js
Add vue-wait/nuxt
to modules section of nuxt.config.js
? VueWait
Options
You can use this options for customize VueWait behavior.
Option Name | Type | Default | Description |
---|---|---|---|
accessorName |
String |
"$wait" |
You can change this value to rename the accessor. E.g. if you rename this to $w , your VueWait methods will be accessible by $w.waits(..) etc. |
useVuex |
Boolean |
false |
Use this value for enabling integration with Vuex store. When this value is true VueWait will store data in Vuex store and all changes to this data will be made by dispatching actions to store |
vuexModuleName |
String |
"wait" |
Name for Vuex store if useVuex set to true, otherwise not used. |
registerComponent |
Boolean |
true |
Registers v-wait component. |
componentName |
String |
"v-wait" |
Changes v-wait component name. |
registerDirective |
Boolean |
true |
Registers v-wait directive. |
directiveName |
String |
"v-wait" |
Changes v-wait directive name. |
? Global Template Helpers
vue-wait provides some helpers to you to use in your templates.
All features can be obtained from $wait property in Vue components.
.any
Returns boolean value if any loader exists in page.
.is(loader String | Matcher)
or .waiting(loader String | Matcher)
Returns boolean value if given loader exists in page.
You can use waiting
alias instead of is
.
Also you can use matcher to make it more flexible:
Please see matcher library to see how to use matchers.
.is(loaders Array<String | Matcher>)
or .waiting(loaders Array<String | Matcher>)
Returns boolean value if some of given loaders exists in page.
.start(loader String)
Starts the given loader.
.end(loader String)
Stops the given loader.
.progress(loader String, current [, total = 100])
Sets the progress of the given loader.
Completing the Progress
To complete the progress, current
value should be set bigger than 100
.
If you total
is given, current
must be bigger than total
.
or
.percent(loader String)
Returns the percentage of the given loader.
? Directives
You can use directives to make your template cleaner.
v-wait:visible='"loader name"'
Shows if the given loader is loading.
v-wait:hidden='"loader name"'
or v-wait:visible.not='"loader name"'
Hides if the given loader is loading.
v-wait:disabled='"loader name"'
Sets disabled="disabled"
attribute to element if the given loader is loading.
v-wait:enabled='"loader name"'
or v-wait:disabled.not='"loader name"'
Removes disabled="disabled"
attribute to element if the given loader is loading.
v-wait:click.start='"loader name"'
Starts given loader on click.
v-wait:click.end='"loader name"'
Ends given loader on click.
v-wait:toggle='"loader name"'
Toggles given loader on click.
v-wait:click.progress='["loader name", 80]'
Sets the progress of given loader on click.
? Loading Action and Getter Mappers
vue-wait provides mapWaitingActions
and mapWaitingGetters
mapper to be used with your Vuex stores.
Let's assume you have a store and async actions called createUser
and updateUser
.
It will call the methods you map and will start loaders while action is resolved.
☢️Advanced Getters and Actions Usage
The Vuex module name is
wait
by default. If you've changed on config, you should get it byrootGetters['<vuex module name>/is']
orrootGetters['<vuex module name>/any']
.
You can access vue-wait
's Vuex getters using rootGetters
in Vuex.
And you can start and end loaders using wait
actions. You must pass root: true
option to the dispatch
method.
waitFor(loader String, func Function [,forceSync = false])
Decorator that wraps function, will trigger a loading and will end loader after the original function (func
argument) is finished.
By default waitFor
return async function, if you want to wrap default sync function pass true
in last argument
Example using with async function
See also examples/wrap-example
? Using v-wait
Component
If you disable registerComponent
option then import and add v-wait
into components
In template, you should wrap your content with v-wait
component to show loading on it.
Better example for a button
with loading state:
⚡️ Making Reusable Loader Components
With reusable loader components, you will be able to use custom loader components as example below. This will allow you to create better user loading experience.

In this example above, the tab gets data from back-end, and the table loads data from back-end at the same time. With vue-wait, you will be able to manage these two seperated loading processes easily:
You may want to design your own reusable loader for your project. You better create a wrapper component called my-waiter
:
Now you can use your spinner everywhere using slot='waiting'
attribute:
? Using with external spinner libraries
You can use vue-wait
with another spinner libraries like epic-spinners or other libraries. You just need to add slot="waiting"
to the component and Vue handles rest of the work.
First register the component,
Then use it in your as a v-wait
's waiting
slot.
... and done!
For other libraries you can use, please see Loaders section of vuejs/awesome-vue.
? Run example
Use npm run dev-vuex
, npm run dev-vue
or npm run dev-wrap
commands.
for running examples locally.