Vue UI Components Documentation
The Vue CheckBox displays a check box that allows the end-user to select a true, false or indeterminate condition. This guide adds the Vue CheckBox (jqxCheckBox) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxcheckbox.vue In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcheckbox.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 CheckBox demo as a Single-File Component:
<template>
<div style="font-family: Verdana Arial; font-size: 12px; width: 400px">
<div style="float: left; width: 400px">
<h3 style="margin-left: 15px">Categories</h3>
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
Entertainment
</JqxCheckBox>
<JqxCheckBox
style="margin-left: 10px; float: left"
:width="120"
:height="25"
:checked="true"
>
<span>Computers</span>
</JqxCheckBox>
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
<span>Sports</span>
</JqxCheckBox>
</div>
<div style="float: left; width: 400px; margin-top: 10px">
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
Health
</JqxCheckBox>
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
<span>Finance</span>
</JqxCheckBox>
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
<span>Travel</span>
</JqxCheckBox>
</div>
<div style="float: left; width: 400px; margin-top: 10px">
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
Music
</JqxCheckBox>
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
<span>Technology</span>
</JqxCheckBox>
<JqxCheckBox style="margin-left: 10px; float: left" :width="120" :height="25">
<span>Publishing</span>
</JqxCheckBox>
</div>
<br />
<div style="float: left; width: 400px; margin-top: 10px">
<h3 style="margin-left: 15px">States</h3>
<JqxCheckBox
@change="checkBox10OnChange($event)"
style="margin-left: 10px; float: left"
:width="120"
:height="25"
:checked="true"
>
<span ref="span10">Checked</span>
</JqxCheckBox>
<JqxCheckBox
@change="checkBox11OnChange($event)"
style="margin-left: 10px; float: left"
:width="120"
:height="25"
:checked="false"
>
<span ref="span11">Unchecked</span>
</JqxCheckBox>
</div>
<div style="float: left; width: 400px; margin-top: 10px">
<JqxCheckBox
@change="checkBox12OnChange($event)"
style="margin-left: 10px; float: left"
:width="120"
:height="25"
:hasThreeStates="true"
:checked="null"
>
<span ref="span12">Indeterminate</span>
</JqxCheckBox>
<JqxCheckBox
style="margin-left: 10px; float: left"
:width="120"
:height="25"
:disabled="true"
>
<span>Disabled</span>
</JqxCheckBox>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcheckbox.vue';
const span10 = ref(null);
const span11 = ref(null);
const span12 = ref(null);
function checkBox10OnChange(event) {
let checked = event.args.checked;
if (checked) {
span10.value.innerHTML = 'Checked';
} else {
span10.value.innerHTML = 'Unchecked';
}
}
function checkBox11OnChange(event) {
let checked = event.args.checked;
if (checked) {
span11.value.innerHTML = 'Checked';
} else {
span11.value.innerHTML = 'Unchecked';
}
}
function checkBox12OnChange(event) {
let checked = event.args.checked;
if (checked) {
span12.value.innerHTML = 'Checked';
} else if (checked === false) {
span12.value.innerHTML = 'Unchecked';
} else {
span12.value.innerHTML = 'Indeterminate';
}
}
</script>
<style></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 is triggered when the checkbox's state changes from one state to another.
<script setup>
function onChange(event) {
console.log(event.args);
}
</script>
<template>
<JqxCheckBox @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 myCheckBox = ref(null);
onMounted(() => {
const value = myCheckBox.value.val();
console.log(value);
});
</script>
<template>
<JqxCheckBox ref="myCheckBox" />
</template>
Every component also has setOptions({ … }) and getOptions('name').