Vue UI Components Documentation
The Vue ColorPicker enables the user to easily pick a color. This guide adds the Vue ColorPicker (jqxColorPicker) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxcolorpicker.vue 
In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxColorPicker from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcolorpicker.vue';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.base.css';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.tailwind-blue-dark.css';
With <script setup>, an imported component is ready to use in the template. jqx.base.css is required; the second file is a theme, selected with the theme attribute.
The Default Functionality demo as a Single-File Component:
<template>
<div ref="root">
<JqxScrollView :width="500" :height="350" :slideShow="true" :showButtons="false">
<div>
<div
class="photo"
style="
background-image: url(https://www.jqwidgets.com/vue/images/imageNature1.jpg);
"
></div>
</div>
<div>
<div
class="photo"
style="
background-image: url(https://www.jqwidgets.com/vue/images/imageNature2.jpg);
"
></div>
</div>
<div>
<div
class="photo"
style="
background-image: url(https://www.jqwidgets.com/vue/images/imageNature3.jpg);
"
></div>
</div>
<div>
<div
class="photo"
style="
background-image: url(https://www.jqwidgets.com/vue/images/imageNature4.jpg);
"
></div>
</div>
<div>
<div
class="photo"
style="
background-image: url(https://www.jqwidgets.com/vue/images/imageNature5.jpg);
"
></div>
</div>
</JqxScrollView>
<br />
<label style="margin-left: 5px; font-size: 12px; font-family: Verdana">
Select Frame color
</label>
<br />
<JqxDropDownButton
ref="myDropDown"
style="margin: 3px; float: left"
:width="150"
:height="22"
>
<div style="padding: 3px">
<JqxColorPicker
@colorchange="colorPickerEvent($event)"
:width="220"
:height="220"
:colorMode="'hue'"
>
</JqxColorPicker>
</div>
</JqxDropDownButton>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import JqxScrollView from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxscrollview.vue';
import JqxDropDownButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxdropdownbutton.vue';
import JqxColorPicker from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcolorpicker.vue';
const root = ref(null);
const myDropDown = ref(null);
function getTextElementByColor(color) {
if (color == 'transparent' || color.hex == '') {
return '<div style="text-shadow: none; position: relative; padding-bottom: 2px; margin-top: 2px;">transparent</div>';
}
let nThreshold = 105;
let bgDelta = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
let foreColor = 255 - bgDelta < nThreshold ? 'Black' : 'White';
let element =
'<div style="text-shadow: none; position: relative; padding-bottom: 2px; margin-top: 2px;color:' +
foreColor +
'; background: #' +
color.hex +
'">#' +
color.hex +
'</div>';
return element;
}
function colorPickerEvent(event) {
myDropDown.value.setContent(getTextElementByColor(event.args.color));
root.value.querySelector('.jqx-scrollview').style.borderColor = '#' + event.args.color.hex;
}
onMounted(() => {
myDropDown.value.setContent(getTextElementByColor({ hex: 'FFAABB', r: 255, g: 170, b: 187 }));
});
</script>
<style>
.photo {
width: 500px;
height: 350px;
background-color: #000;
background-position: center;
background-repeat: no-repeat;
}
.jqx-scrollview {
border: 15px solid #ffaabb;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
</style>Options are attributes. Bind values from the script with :, for example :width="850".
Listen to an event with @ and its name. For example, colorchange: This event is triggered when a new color is picked.
<script setup>
function onColorchange(event) {
console.log(event.args);
}
</script>
<template>
<JqxColorPicker @colorchange="onColorchange" />
</template>
Call methods through a template ref. For example, getColor: Gets the color.
<script setup>
import { ref, onMounted } from 'vue';
const myColorPicker = ref(null);
onMounted(() => {
const result = myColorPicker.value.getColor();
console.log(result);
});
</script>
<template>
<JqxColorPicker ref="myColorPicker" />
</template>
Every component also has setOptions({ … }) and getOptions('name').