Vue UI Components Documentation
The Vue RadioButton lets users make one choice among a set of mutually exclusive, related options. This guide adds the Vue RadioButton (jqxRadioButton) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxradiobutton.vue In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxRadioButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxradiobutton.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 RadioButton demo as a Single-File Component:
<template>
<div>
<h3>House Contract</h3>
<JqxRadioButton
@change="firstBtnOnChange($event)"
:width="250"
:height="25"
:checked="true"
>
<span>12 Months Contract</span>
</JqxRadioButton>
<JqxRadioButton @change="secondBtnOnChange($event)" :width="250" :height="25">
<span>6 Months Contract</span>
</JqxRadioButton>
<JqxRadioButton @change="thirdBtnOnChange($event)" :width="250" :height="25">
<span>3 Months Contract</span>
</JqxRadioButton>
<JqxRadioButton :width="250" :height="25" :disabled="true">
<span>1 Month Contract</span>
</JqxRadioButton>
<div style="margin-top: 10px">
<div>Events:</div>
<div ref="eventsLog"></div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
import JqxRadioButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxradiobutton.vue';
const eventsLog = ref(null);
let count = 0;
function clearLog() {
let log = eventsLog.value;
if (count >= 2) {
log.innerHTML = '';
count = 0;
}
count++;
}
function firstBtnOnChange(event) {
clearLog();
let log = eventsLog.value;
let checked = event.args.checked;
if (checked) {
log.innerHTML += '<div><span>Checked: 12 Months Contract</span></div>';
} else {
log.innerHTML += '<div><span>Unchecked: 12 Months Contract</span></div>';
}
}
function secondBtnOnChange(event) {
clearLog();
let log = eventsLog.value;
let checked = event.args.checked;
if (checked) {
log.innerHTML += '<div><span>Checked: 6 Months Contract</span></div>';
} else {
log.innerHTML += '<div><span>Unchecked: 6 Months Contract</span></div>';
}
}
function thirdBtnOnChange(event) {
clearLog();
let log = eventsLog.value;
let checked = event.args.checked;
if (checked) {
log.innerHTML += '<div><span>Checked: 3 Months Contract</span></div>';
} else {
log.innerHTML += '<div><span>Unchecked: 3 Months Contract</span></div>';
}
}
</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 Radio Button's state changes from one state to another.
<script setup>
function onChange(event) {
console.log(event.args);
}
</script>
<template>
<JqxRadioButton @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 myRadioButton = ref(null);
onMounted(() => {
const value = myRadioButton.value.val();
console.log(value);
});
</script>
<template>
<JqxRadioButton ref="myRadioButton" />
</template>
Every component also has setOptions({ … }) and getOptions('name').