Vue UI Components Documentation
The Vue Slider represents a flexible Slider that lets the user select from a range of values by moving a thumb along a track. This guide adds the Vue Slider (jqxSlider) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxslider.vue 
In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxSlider from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxslider.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 style="width: 550px">
<div style="height: 180px">
<div style="float: left">
<span style="font-style: italic">Red</span>
<JqxSlider
ref="redSlider"
@change="setColor()"
:height="60"
:min="0"
:max="255"
:tickLabelFormatFunction="tickLabelFormatFunction"
:value="0"
:step="25.5"
:mode="'fixed'"
:tooltipFormatFunction="tooltipFormatFunction"
:showTickLabels="true"
:tooltip="true"
:ticksFrequency="25.5"
>
</JqxSlider>
<span style="font-style: italic">Green</span>
<JqxSlider
ref="greenSlider"
@change="setColor()"
:height="60"
:min="0"
:max="255"
:tickLabelFormatFunction="tickLabelFormatFunction"
:value="0"
:step="25.5"
:mode="'fixed'"
:tooltipFormatFunction="tooltipFormatFunction"
:showTickLabels="true"
:tooltip="true"
:ticksFrequency="25.5"
>
</JqxSlider>
<span style="font-style: italic">Blue</span>
<JqxSlider
ref="blueSlider"
@change="setColor()"
:height="60"
:min="0"
:max="255"
:tickLabelFormatFunction="tickLabelFormatFunction"
:value="255"
:step="25.5"
:mode="'fixed'"
:tooltipFormatFunction="tooltipFormatFunction"
:showTickLabels="true"
:tooltip="true"
:ticksFrequency="25.5"
>
</JqxSlider>
</div>
<div class="jqx-rc-all colorBlock" id="colorBlock">
<div id="colorLabel"></div>
</div>
</div>
<JqxCheckBox @change="checkBoxOnChange($event)" :width="200" :checked="false">
Smooth Thumb Drag
</JqxCheckBox>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import JqxSlider from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxslider.vue';
import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcheckbox.vue';
const redSlider = ref(null);
const greenSlider = ref(null);
const blueSlider = ref(null);
function checkBoxOnChange(event) {
const checked = event.args.checked;
const value = checked ? 'default' : 'fixed';
redSlider.value.mode = value;
greenSlider.value.mode = value;
blueSlider.value.mode = value;
}
function setColor() {
const red = fixHex(Math.round(redSlider.value.value).toString(16)),
green = fixHex(Math.round(greenSlider.value.value).toString(16)),
blue = fixHex(Math.round(blueSlider.value.value).toString(16));
document.querySelector('#colorBlock').style.backgroundColor = '#' + red + green + blue;
document.querySelector('#colorLabel').innerHTML = ('#' + red + green + blue).toUpperCase();
const color = getTextElement({
r: parseInt(red, 16),
g: parseInt(green, 16),
b: parseInt(blue, 16)
});
document.querySelector('#colorLabel').style.color = color;
}
function fixHex(hex) {
return hex.length < 2 ? '0' + hex : hex;
}
function getTextElement(color) {
const nThreshold = 105;
const bgDelta = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
const foreColor = 255 - bgDelta < nThreshold ? 'Black' : 'White';
return foreColor;
}
function tickLabelFormatFunction(value) {
if (value == 0) return value;
if (value == 255) return value;
return '';
}
function tooltipFormatFunction(value) {
if (redSlider.value.mode === 'default') {
if (value < 10) return new Number(value.toPrecision(3));
if (value > 10 && value < 100) return new Number(value.toPrecision(4));
else return new Number(value.toPrecision(5));
} else {
if (value < 10) return new Number(value.toPrecision(3));
if (value > 10 && value < 256) return new Number(value.toPrecision(4));
}
}
onMounted(() => {
setColor();
});
</script>
<style>
.colorBlock {
border: 1px solid #aaa;
width: 200px;
height: 200px;
float: right;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.colorLabel {
padding: 6px;
}
/* under the colour block, clear of the sliders (their height depends on the theme) */
.jqx-checkbox {
float: right;
clear: right;
margin-top: 20px;
}
</style>Options are attributes. Bind values from the script with :, for example :width="850".
Listen to an event with @ and its name. For example, change: This event is triggered when the value of the slider is changed.
<script setup>
function onChange(event) {
console.log(event.args);
}
</script>
<template>
<JqxSlider @change="onChange" />
</template>
Call methods through a template ref. For example, val: Sets or gets the value.
<script setup>
import { ref, onMounted } from 'vue';
const mySlider = ref(null);
onMounted(() => {
const value = mySlider.value.val();
console.log(value);
});
</script>
<template>
<JqxSlider ref="mySlider" />
</template>
Every component also has setOptions({ … }) and getOptions('name').