Vue Color Pickers
Vue Color is a comprehensive collection of performant and highly customizable color picker components designed for Vue.js applications. The current stable version is 3.3.3. The library is actively maintained with regular patch releases addressing bug fixes and dependency updates, and minor versions introduce new features like additional slider components (e.g., `<HSLSliders />`, `<HSVSliders />`, `<RGBSliders />`) and dark mode support. A major rewrite to v3.0.0 moved the library to TypeScript and full Vue 3 support, while also maintaining compatibility with Vue 2.7. Key differentiators include its modular and tree-shakable design, full TypeScript typings, SSR-friendliness, and built-in accessibility and dark mode support. It uses `tinycolor2` internally for robust color parsing and conversion, allowing `v-model` to preserve the input color format.
Common errors
-
ReferenceError: TouchEvent is not defined
cause This error occurs in environments where the `TouchEvent` global object is not present, such as some older browser versions or during server-side rendering (SSR) if not properly handled.fixThis issue was specifically fixed in `vue-color` v3.0.2. Ensure you are using version 3.0.2 or later. For SSR, ensure that any client-side-only components, like color pickers, are loaded dynamically or rendered conditionally on the client-side (e.g., using `<client-only>` in Nuxt). -
Failed to resolve component: ComponentName
cause This typically means the component was not correctly imported or registered in your Vue application, or you are trying to use a default import for a named export.fixVerify that you are using named imports for all components (e.g., `import { ChromePicker } from 'vue-color'`) and that the component is either globally registered or locally imported and registered in the `<script setup>` block or `components` option of your Vue component. -
Error: Cannot find module 'vue-color/style.css'
cause The path to the stylesheet is incorrect, or the build system is not configured to handle CSS imports.fixEnsure the import statement `import 'vue-color/style.css'` is exactly as specified. If using a custom build setup, verify that your bundler (e.g., Webpack, Vite) has appropriate loaders configured to process CSS files.
Warnings
- breaking Version 3.0.0 was a complete rewrite, introducing full TypeScript support and migrating exclusively to Vue 3. This means that applications using Vue 2.x (prior to 2.7) are not compatible with `vue-color` v3 and should remain on previous major versions or migrate to Vue 2.7+ for partial compatibility.
- breaking With the v3 rewrite, CommonJS `require()` syntax is no longer officially supported for importing components. The library is designed for ESM imports.
- gotcha The `v-model` prop accepts various color formats (hex, rgb, hsl, object) and attempts to preserve the input format. However, mixing formats or expecting a specific output format without explicit conversion can lead to unexpected behavior in downstream components.
- gotcha For Vue 2.7 projects, `vue-color` v3 supports compatibility. However, specific usage patterns might differ slightly from a pure Vue 3 setup, especially regarding reactivity primitives like `ref` and `defineModel` (which is Vue 3 only).
Install
-
npm install vue-color -
yarn add vue-color -
pnpm add vue-color
Imports
- ChromePicker
const ChromePicker = require('vue-color')import { ChromePicker } from 'vue-color' - style.css
import 'vue-color/style.css'
- SliderPicker
import SliderPicker from 'vue-color'
import { SliderPicker } from 'vue-color'
Quickstart
import { createApp } from 'vue';
import App from './App.vue';
import 'vue-color/style.css';
createApp(App).mount('#app');
// In App.vue
<template>
<div style="padding: 20px;">
<h1>Pick a Color</h1>
<ChromePicker v-model="color" />
<p style="margin-top: 20px;">Selected Color: {{ color }}</p>
</div>
</template>
<script setup lang="ts">
import { ChromePicker } from 'vue-color';
import { ref } from 'vue';
const color = ref('#68CCCA');
</script>