Vue Spinner Components
vue-spinner is a collection of 16 highly customizable loading spinner components for Vue.js applications. Currently at version 3.0.1, it specifically targets Vue 3.5+ using the Composition API, offering full TypeScript support with detailed prop types, and ships with ESM and UMD outputs for broad compatibility. The library differentiates itself by providing a variety of pre-built, production-ready spinners based on the Halogen project, covering common loading patterns with props for `loading` state, `color`, `size` (or `height`/`width`), `margin`, and `radius`. While it recently underwent a major overhaul for Vue 3 compatibility, previous versions (like 1.0.4) are available for Vue 1.x projects, establishing a clear versioning strategy tied to Vue's major releases. The project appears to have an active maintenance cadence, with recent updates adding significant test coverage via Vitest.
Common errors
-
Failed to resolve component: <component-name>
cause The spinner component was not correctly imported or registered with the Vue application.fixEnsure you either use a named import like `import { PulseLoader } from 'vue-spinner'` and list it in `components: { PulseLoader }`, or globally register it with `app.component('PulseLoader', PulseLoader)`. -
[Vue warn]: Component <Component> is missing template or render function.
cause Attempting to import a `.vue` file component directly in an environment that doesn't support Vue SFC compilation (e.g., a vanilla JS file without a build step, or a mismatched bundler configuration).fixWhen importing individual components like `import PulseLoader from 'vue-spinner/src/PulseLoader.vue'`, ensure your build setup (Vite, Webpack) is correctly configured to process `.vue` Single File Components. For most cases, `import { PulseLoader } from 'vue-spinner'` is preferred as it imports the pre-compiled component.
Warnings
- breaking Version 3.x of vue-spinner is a complete rewrite for Vue 3.x and is incompatible with Vue 1.x.
- gotcha While many spinners use a `size` prop, some like `FadeLoader` and `ScaleLoader` use `height` and `width` instead. Check the documentation for specific spinner props.
- gotcha Global CSS styles could potentially conflict with the spinner styles if not properly scoped. Although `vue-spinner` v3 now uses scoped CSS, external styles might still interfere.
Install
-
npm install vue-spinner -
yarn add vue-spinner -
pnpm add vue-spinner
Imports
- PulseLoader
const PulseLoader = require('vue-spinner')import { PulseLoader } from 'vue-spinner' - PulseLoader
import PulseLoader from 'vue-spinner/src/PulseLoader.vue'
- VueSpinner
const { PulseLoader, GridLoader } = VueSpinner - types
import type { PulseLoaderProps } from 'vue-spinner'
Quickstart
import { ref } from 'vue'
import { PulseLoader } from 'vue-spinner'
const App = {
setup() {
const loading = ref(true)
const color = ref('#5dc596')
const size = ref('15px')
// Simulate loading state change after a few seconds
setTimeout(() => {
loading.value = false;
}, 3000);
return {
loading,
color,
size
}
},
template: `
<div style="display: flex; justify-content: center; align-items: center; min-height: 100px;">
<pulse-loader :loading="loading" :color="color" :size="size"></pulse-loader>
<p v-if="!loading" style="margin-left: 10px;">Content Loaded!</p>
</div>
`,
components: { PulseLoader }
}
// In a real Vue app, you would mount this:
// import { createApp } from 'vue'
// createApp(App).mount('#app')