Vue UI Components Documentation
The Vue DropDownButton shows any content in a drop-down that opens from a button. This guide adds the Vue DropDownButton (jqxDropDownButton) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-vue3/vue_jqxdropdownbutton.vue In a Vue 3 project (to start one, see Getting started with Vue), add the package:
npm install jqwidgets-scripts
import JqxDropDownButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxdropdownbutton.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 DropDown Button demo as a Single-File Component:
<template>
<div>
<JqxDropDownButton ref="myDropDownButton" style="float: left" :width="150" :height="25">
<JqxTree ref="myTree" @select="treeOnSelect($event)" :width="200">
<ul>
<li item-selected="true">Home</li>
<li item-expanded="true">
Solutions
<ul>
<li>Education</li>
<li>Financial services</li>
<li>Government</li>
<li>Manufacturing</li>
<li>
Solutions
<ul>
<li>eLearning</li>
<li>Mobile</li>
<li>RIA</li>
<li>Training</li>
</ul>
</li>
</ul>
</li>
<li>
Products
<ul>
<li>PC products</li>
<li>Mobile products</li>
<li>All products</li>
</ul>
</li>
</ul>
</JqxTree>
</JqxDropDownButton>
<div style="float: left; margin-top: 5px; margin-left: 30px">
<JqxCheckBox @change="checkBoxOnChange($event)"> Open On Mouse Over </JqxCheckBox>
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import JqxDropDownButton from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxdropdownbutton.vue';
import JqxTree from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxtree.vue';
import JqxCheckBox from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxcheckbox.vue';
const myTree = ref(null);
const myDropDownButton = ref(null);
function treeOnSelect(event) {
let item = myTree.value.getItem(event.args.element);
let dropDownContent = `<div style="position: relative; margin-left: 3px; margin-top: 4px;">${item.label}</div>`;
myDropDownButton.value.setContent(dropDownContent);
}
function checkBoxOnChange(event) {
myDropDownButton.value.autoOpen = event.args.checked;
}
onMounted(() => {
myDropDownButton.value.setContent(
'<div style="position: relative; margin-left: 3px; margin-top: 4px;">Home</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, open: This event is triggered when the button's popup is opened.
<script setup>
function onOpen(event) {
console.log(event.args);
}
</script>
<template>
<JqxDropDownButton @open="onOpen" />
</template>
Call methods through a template ref. For example, open: Shows the button's content.
<script setup>
import { ref, onMounted } from 'vue';
const myDropDownButton = ref(null);
onMounted(() => {
myDropDownButton.value.open();
});
</script>
<template>
<JqxDropDownButton ref="myDropDownButton" />
</template>
Every component also has setOptions({ … }) and getOptions('name').