Vue UI Components Documentation
The Vue ScrollBar provides a scroll bar that has a sliding thumb whose position corresponds to a value. This guide adds the Vue ScrollBar (jqxScrollBar) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxscrollbar.vue In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxScrollBar from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxscrollbar.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>
<div style="margin-bottom: 10px" ref="verticalLabel">Vertical</div>
<JqxScrollBar
@valueChanged="onValueChangedVertical($event)"
:width="18"
:height="280"
:min="0"
:max="1000"
:vertical="true"
/>
<div style="margin: 10px 0" ref="horizontalLabel">Horizontal</div>
<JqxScrollBar
@valueChanged="onValueChangedHorizontal($event)"
:width="280"
:height="18"
:min="0"
:max="1000"
/>
</div>
</template>
<script setup>
import { ref } from 'vue';
import JqxScrollBar from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxscrollbar.vue';
const verticalLabel = ref(null);
const horizontalLabel = ref(null);
function onValueChangedVertical(event) {
verticalLabel.value.innerHTML = 'Vertical (' + parseInt(event.currentValue) + ')';
}
function onValueChangedHorizontal(event) {
horizontalLabel.value.innerHTML = 'Horizontal (' + parseInt(event.currentValue) + ')';
}
</script>
Options are attributes. Bind values from the script with :, for example :width="850".
Listen to an event with @ and its name. For example, valueChanged: This event is triggered when the value is changed.
<script setup>
function onValueChanged(event) {
console.log(event.args);
}
</script>
<template>
<JqxScrollBar @valueChanged="onValueChanged" />
</template>
Call methods through a template ref. For example, isScrolling: Returns true, if the user is scrolling.
<script setup>
import { ref, onMounted } from 'vue';
const myScrollBar = ref(null);
onMounted(() => {
const result = myScrollBar.value.isScrolling();
console.log(result);
});
</script>
<template>
<JqxScrollBar ref="myScrollBar" />
</template>
Every component also has setOptions({ … }) and getOptions('name').