Vue UI Components Documentation
This page explains how jQWidgets Vue components fit into a Vite project written with the Composition API and <script setup>: props, template refs, events and v-model. The example is an input with autocomplete, bound two ways to a ref.
Two commands create a Vue 3 project on Vite. Use either one:
npm create vue@latest runs create-vue, the official Vue scaffolding tool. It can add TypeScript, the router, Pinia, tests and ESLint.npm create vite@latest my-app -- --template vue-ts creates a minimal Vue and TypeScript project from the Vite templates.This page uses create-vue. Answer Yes to TypeScript, then add jQWidgets:
npm create vue@latest my-app
cd my-app
npm install
npm install jqwidgets-scripts
Add one setting to vite.config.ts, so that npm run build does not stop with Unexpected token Semicolon: some jQWidgets themes still contain Internet Explorer CSS hacks (*zoom: 1), which Vite's CSS minifier rejects, and errorRecovery drops those lines instead of stopping the build. Keep the rest of the file create-vue wrote:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
// Some jQWidgets themes still contain Internet Explorer CSS hacks (*zoom: 1), which Vite's
// CSS minifier rejects: errorRecovery drops those lines instead of stopping the build.
css: { lightningcss: { errorRecovery: true } },
})
An app that also uses the Grid, Calendar, DateTimeInput, Form or Scheduler needs one more addition for npm run dev, shown in Add a Grid to a Vue 3 app.
Replace src/main.ts. Vite bundles the CSS files and the images and fonts they reference:
import { createApp } from 'vue';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.base.css';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.tailwind-blue-dark.css';
import App from './App.vue';
createApp(App).mount('#app');
The Vue components are plain JavaScript files, so TypeScript's strict mode rejects importing them (TS7016: Could not find a declaration file). Declare them once in a new file, src/jqwidgets-vue3.d.ts:
// src/jqwidgets-vue3.d.ts
declare module 'jqwidgets-scripts/jqwidgets-vue3/*.vue' {
import type { DefineComponent } from 'vue';
const component: DefineComponent<Record<string, any>, Record<string, any>, any>;
export default component;
}
Replace src/App.vue:
<script setup lang="ts">
import { ref } from 'vue';
import JqxInput from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxinput.vue';
// Methods of the input that this component calls.
interface InputMethods {
focus: () => void;
}
// Template ref: the name matches ref="myInput" in the template.
const myInput = ref<InputMethods | null>(null);
// v-model keeps this ref and the input's text in sync.
const country = ref('Hong Kong');
const countries = [
'Argentina', 'Australia', 'Austria', 'Belgium', 'Brazil', 'Bulgaria', 'Canada', 'Chile', 'China',
'Denmark', 'Finland', 'France', 'Germany', 'Greece', 'Hong Kong', 'India', 'Ireland', 'Italy', 'Japan',
'Mexico', 'Netherlands', 'Norway', 'Poland', 'Portugal', 'Spain', 'Sweden', 'Switzerland',
'United Kingdom', 'United States'
];
const lastSelected = ref('');
// The select event fires when the user picks an item from the list.
// A native text-selection event on the input has no args; skip it.
function onSelect(event: any) {
if (event.args) {
lastSelected.value = event.args.item.label;
}
}
function clear() {
country.value = '';
myInput.value?.focus();
}
</script>
<template>
<main>
<p>The value is: {{ country }}</p>
<JqxInput
ref="myInput"
v-model="country"
theme="tailwind-blue-dark"
:width="250"
:height="30"
:source="countries"
placeHolder="Type a country"
@select="onSelect"
/>
<button type="button" @click="clear">Clear</button>
<p v-if="lastSelected">Picked from the list: {{ lastSelected }}</p>
</main>
</template>

| You want to | Write |
|---|---|
| Use a component | Import it; there is no components option. |
| Pass a widget option | A prop: :width="250", or :source="countries" for a value from the script. |
| Update an option | Bind it to a ref or computed and change the value; the component applies it. |
| Call a method | A template ref: const myInput = ref(null) plus ref="myInput", then myInput.value.focus(). |
| Handle an event | @select="onSelect", with the widget's event name. |
| Run code after the widget exists | onMounted(() => { … }). |
| Two-way binding | v-model on input components such as JqxInput, JqxComboBox, JqxDateTimeInput or JqxSlider. |
npm run dev
Open http://localhost:5173. Type a few letters to see the suggestions; the text above the input follows what you type.
A Grid needs a few more lines, because it reads its data through jqx.dataAdapter. Add a Grid to a Vue 3 app walks through it, and Add a Chart to a Vue 3 app does the same for charts.
Live examples of every Vue component: jqwidgets.com/vue.