Vue Loaders
vue-loaders is a JavaScript library providing Vue.js component wrappers for the popular loaders.css library, which offers a collection of animated loading indicators. The current stable version is 4.1.4. The project actively maintains support for both Vue 2 and Vue 3, with v4.0.0 introducing compatibility for Vue 3. Releases are made on an as-needed basis for features and bug fixes, indicated by recent minor version bumps and a major version increment for Vue 3 support. It differentiates itself by offering flexible integration options: developers can register all loaders globally via a plugin, import individual loader components directly, or dynamically render loaders using a single vue-loaders component with a name prop. It also ships with TypeScript types, improving developer experience in typed environments.
Common errors
-
[Vue warn]: Unknown custom element: <vue-loaders-ball-beat> - did you register the component correctly?
cause The loader component was not globally registered via `Vue.use(VueLoaders)` or locally registered within the Vue component where it's being used.fixAdd `Vue.use(VueLoaders);` to your application's entry file (e.g., `main.js` or `main.ts`), or import specific loaders and register them in your component's `components` option: `{ components: { VueLoadersBallBeat } }`. -
Loader appears as static dots/shapes, no animation or incorrect styling.
cause The required `vue-loaders/dist/vue-loaders.css` stylesheet was not properly imported or linked in the application.fixEnsure `import 'vue-loaders/dist/vue-loaders.css';` is included in your main JavaScript/TypeScript file or that the CSS file is otherwise correctly loaded by your build system.
Warnings
- breaking Version 4.0.0 introduced breaking changes by adding initial support for Vue 3. Projects using Vue 2 should remain on v3.x.x to avoid compatibility issues, or migrate their application to Vue 3.
- gotcha Forgetting to import the `vue-loaders.css` stylesheet will result in loaders appearing as static, unstyled elements without animation, making them effectively invisible or broken.
- gotcha While `Vue.use(VueLoaders)` is convenient for global registration of all loaders, it might lead to a larger bundle size if only a few specific loaders are needed. Consider importing and registering individual components locally for better tree-shaking.
- gotcha The `color` prop directly sets the loader's color. If you want the loader to inherit its color from a parent element's text color, you must explicitly set the `color` prop to `'currentColor'`.
Install
-
npm install vue-loaders -
yarn add vue-loaders -
pnpm add vue-loaders
Imports
- VueLoaders
const VueLoaders = require('vue-loaders');import VueLoaders from 'vue-loaders';
- VueLoadersBallBeat
import { VueLoadersBallBeat } from 'vue-loaders';import VueLoadersBallBeat from 'vue-loaders/dist/loaders/ball-beat';
- CSS Styles
import 'loaders.css/loaders.min.css';
import 'vue-loaders/dist/vue-loaders.css';
Quickstart
import Vue from 'vue/dist/vue.esm.browser';
import 'vue-loaders/dist/vue-loaders.css';
import VueLoaders from 'vue-loaders';
Vue.use(VueLoaders);
const template = `
<div>
<vue-loaders-ball-beat color="red" scale="1"></vue-loaders-ball-beat>
<hr/>
<vue-loaders name="ball-beat" color="red" scale="1"></vue-loaders>
</div>
`;
new Vue({
template
}).$mount('#app');