Vue UI Components Documentation
Vue Button Component
The Button component for Vue - configured to show textual content only, or to display a predefined icon, an image, or a custom icon, or yet a combination of textual and image content.
Prerequisites
Refer to Vue Getting Started before you start with this help topic.
Configuration
After you have created your App.vue file, here is how you should structure it:
The Button component for Vue requires the following import:
Add the jqxButton component to the components section of the the Vue class:
Template
The App.vue has a <template>
structural tag where we determine the application structure.
There we will also set the tags for the new components - <JqxButton/>
<template> <JqxButton ref="button" :width="width" :height="height" :value="value" @click="click()"> Button </JqxButton></template>
Properties
The properties of the <JqxButton/> component are defined in the data
member of the Vue class.
We should put them in the return object of the data function:
data: function () { return { width: 120, height: 30, value: "Button" }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxButton ref="button" @click="click()"> Button</JqxButton>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { click: function () { // Do something... }}
Methods
To use a component's method we should have its reference. In Vue we refer to a component by the special $refs
property.
Before that we need to add the desired name reference to that component:
<JqxButton ref="button"></JqxButton>
Here how you can use a component's method:
this.$refs.button.val('Clicked');
methods: { // Add here all used callbacks and/or events click: function () { // Do something when clicking on the button this.$refs.button.val('Clicked'); }}
If we want to add additional methods we should also implement them in the methods
member.
In case we need to do some precalculation or something else before the components are rendered, we should use the beforeCreate
member.
It depends on the case.
If you have followed the above steps, you App.vue file would look like this:
App.vue:
<template> <JqxButton ref="button" :width="width" :height="height" :value="value" @click="click()"> Button </JqxButton></template> <script> // Import the components that will be used import JqxButton from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxbuttons.vue'; export default { components: { // Adding imported widgets here JqxButton }, data: function () { // Define properties which will use in the widget return { width: 120, height: 30, value: "Button" } }, beforeCreate: function () { // Add here any data where you want to transform before components be rendered }, methods: { // Add here all used callbacks and/or events click: function () { // Do something when clicking on the button this.$refs.button.val('Clicked'); } } }</script> <style></style>
Button Examples
<template> <div> <div style='margin-top: 20px'> <JqxButton ref="button" :width="120" :height="40" :textPosition="'center'" @click="buttonClicked()"> Button </JqxButton> </div> <div style='margin-top: 20px'> <JqxButton ref="submitButton" :width="120" :height="40" :textPosition="'center'" @click="submitButtonClicked()"> Submit </JqxButton> </div> <div style='margin-top: 20px'> <JqxButton ref="imageButton" :width="120" :height="40" :textPosition="'center'" :imgSrc="'../images/facebook.png'" @click="imageButtonClicked()"> </JqxButton> </div> <div style='margin-top: 20px'> <JqxButton ref="myTextImageButton" :width="120" :height="40" :textImageRelation="'imageBeforeText'" :textPosition="'left'" :imgSrc="'../images/twitter.png'" @click="textImageButtonClicked()"> Button </JqxButton> </div> <div style='margin-top: 20px'> <JqxButton ref="myHTMLButton" :width="120" :height="40" :textPosition="'center'" @click="hTMLButtonClicked()"> <span style='font-weight: bold; '>HTML Button</span> </JqxButton> </div> <div style='margin-top: 20px'> <JqxButton ref="disabledButton" :width="120" :height="40" :textPosition="'center'" :disabled="true"> Disabled </JqxButton> </div> <div style='margin-top:1em'>Events:</div> <div ref="events"></div> </div></template> <script> import JqxButton from 'jqwidgets-scripts/jqwidgets-vue/vue_jqxbuttons.vue'; export default { components: { JqxButton }, methods: { buttonClicked: function () { this.$refs.events.innerHTML = '<span>Button Clicked</span>'; }, submitButtonClicked: function () { this.$refs.events.innerHTML = '<span>Submit Button Clicked</span>'; }, imageButtonClicked: function () { this.$refs.events.innerHTML = '<span>Image Button Clicked</span>'; }, textImageButtonClicked: function () { this.$refs.events.innerHTML = '<span>Text/Image Button Clicked</span>'; this.$refs.myTextImageButton.textImageRelation = "textBeforeImage"; this.$refs.myTextImageButton.imgPosition = "left"; this.$refs.myTextImageButton.textPosition = "center"; }, hTMLButtonClicked: function () { this.$refs.events.innerHTML = '<span>HTML Button Clicked</span>'; this.$refs.myHTMLButton.textPosition = "top"; this.$refs.myHTMLButton.value = "<span style='font-style: italic; position: relative; right: 8px'>Thanks for clicking me!</span>"; } } }</script> <style></style>