
Multiple Process Loader Management for Vue and (optionally) Vuex.
⚠️ Even it's named as
vuex-loading
, Vuex is completely optional.

vuex-loading 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
$ yarn add vuex-loading# or if you using npm $ npm install vuex-loading
📖 Usage
Vue // add VueLoading as Vue plugin
Then you should register VueLoading
module:
el: '#app' store vueLoading: // Defaults values are following: useVuex: false // Uses Vuex to manage loading state vuexModuleName: 'loading' // Vuex module name registerComponent: true // Registers `v-loading` component componentName: 'v-loading' // <v-loading> component name, you can set `my-loader` etc. registerDirective: true // Registers `v-loading` directive directiveName: 'loading' // <span v-loading /> directive name, you can set `my-loader` etc. ;
♻️ Usage with Vuex
Simply set useVuex
parameter to true
and optionally override
vuexModuleName
VueVue // add VueLoading as Vue plugin
Then you should register vueLoading
module:
el: '#app' store vueLoading: useVuex: true // You must pass this option `true` to use Vuex vuexModuleName: 'vuex-example-module' // It's optional, `loading` by default. ;
Now VueLoading
will use Vuex
store for data management which can be traced in Vue DevTools > Vuex

🔁 VueLoading Options
You can use this options for customize VueLoading behavior.
accessorName
String
value, $vueLoading
by default, you can change this value to rename the accessor.
E.g. if you rename this to $l
, your VueLoading
methods will be accessible by $l.isLoading(..)
etc.
useVuex
Boolean
value, false
by default, use this value for enabling
integration with Vuex
store
When this value is true VueLoading
will store data in Vuex
store
and all changes to this data will be made by dispatching actions to store
vuexModuleName
String
value, loading
by default.
Name for Vuex
store if useVuex
set to true, otherwise not used.
registerComponent
Boolean
value, true
by default, register v-loading
component.
componentName
String
value, v-loading
by default, changes v-loading
component name.
🌈 Global Template Helpers
vuex-loading provides some helpers to you to use in your templates. All features can be obtained from $vueLoading property in Vue components.
.anyLoading
Returns boolean value if any loader exists in page.
Please wait...
.isLoading(loader String | RegExp)
Returns boolean value if given loader exists in page.
Creating User...
Also you can use matcher to make it more flexible:
Please see matcher library to see how to use matchers.
Creating something...
.isLoading(loaders Array<String>)
Returns boolean value if some of given loaders exists in page.
Creating User...
.startLoading(loader String)
Starts the given loader.
Create User
.endLoading(loader String)
Stops the given loader.
Cancel
🏹 Directives
You can use directives to make your template cleaner.
v-loading:visible='"loader name"'
Shows if the given loader is loading.
Creating User...
v-loading:hidden='"loader name"'
or v-loading:visible.not='"loader name"'
Hides if the given loader is loading.
Some Content
v-loading:disabled='"loader name"'
Sets disabled="disabled"
attribute to element if the given loader is loading.
v-loading:enabled='"loader name"'
or v-loading:disabled.not='"loader name"'
Removes disabled="disabled"
attribute to element if the given loader is loading.
Abort Request
v-loading:click.start='"loader name"'
Starts given loader on click.
Start loader
v-loading:click.end='"loader name"'
Ends given loader on click.
End loader
v-loading:toggle='"loader name"'
Toggles given loader on click.
Toggles the loader
🔌 Loading Action Mappers
vuex-loading provides mapLoadingActions
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.
// ... methods: ... // ...
createActionHelpers
?
😱 What happened to old We've removed them. Since they were just calling dispatch
, you can just write like following example. We don't like complexity.
//...actions: async { const loader = 'getting users'; ; await UserService; ; }//...
Using mapLoadingActions
or wrapLoading
instead is a better way.
wrapLoading(loader String, func Function, [,force_sync = false])
Decorator that wraps function, will trigger a loading and will end loader after the original function (func
argument) is finished.
By default wrapLoading
return async function, if you want to wrap default sync function pass true
in last argument
Example using with async function
...methods: fetchDataFromApi: ...
See also examples/wrap-example
v-loading
Component
💧 Using If you disable registerComponent
option then import and add v-loading
into components
components: 'v-loading': vLoading
In template, you should wrap your content with v-loading
component to show loading on it.
This will be shown when "fetching data" loader starts. This will be shown when "fetching data" loader ends.
Better example for a button
with loading state:
Creating User... Create User
⚡️ 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 vuex-loading, you will be able to manage these two seperated loading processes easily:
div v-loading(loader='fetching tabs') template(slot='loading') b-tabs template(slot='tabs') b-nav-item(active disabled) v-icon(name='circle-o-notch', spin) b-tabs template(slot='tabs') b-nav-item(v-for='tab in tabs') {{ tab.name }} v-loading(loader='fetching data') table-gradient-spinner(slot='loading') table tr(v-for='row in data') // ...
You may want to design your own reusable loader for your project. You better create a wrapper component called my-spinner
:
<!-- MySpinner.vue --> tr: loading: Yükleniyor... en: loading: Loading... div.loading-spinner //- Uses vue-awesome spinner v-icon(name='refresh', spin) span {{ $t('loading') }}
Now you can use your spinner everywhere using slot='loading'
attribute:
v-loading(loader='fetching data') my-spinner(slot='loading') div p My main content after fetching data...
🚌 Run example
Use npm run dev-vuex
, npm run dev-vue
or npm run dev-wrap
commands.
for running examples locally.
🎯 Contributors
- Fatih Kadir Akın, (creator)
- Igor, (maintainer, made Vuex-free)
🔑 License
MIT © Fatih Kadir Akın