Vue.js for UI Components Creation
Last updated
Was this helpful?
Last updated
Was this helpful?
Vue.js is a JavaScript framework that is very convenient for UI components creation in Aitheon Apps Editor.
The editor uses the v2 version of the framework. Discover the native before we go through the sample component content.
The sample UI component creates a simple button, that passes on a string type message (The standard doesn't do this - it works differently).
The sample project, which you can use as a template, contains two components folders: example-button (a UI component sample) and example-uppercase.
The difference in a UI component example - two files that provide the UI element appearance and visual behavior rules: the example-button folder contains a ui sub-folder with an ExampleButton.vue file and a helpers.js file.
This file defines the appearance behavior of the button.
The file contains a specific part for the UI component. (Explore the part after a corresponding note there: '// call this only for UI Component').
The Vue.js framework lets you group your <template>
, corresponding <script>
, and CSS <style>
all together in a single file ending in .vue.
In a template for a UI element component the ExampleButton.vue file follows the one-file style.
You can still separate JavaScript and CSS into separate files if you want, and import them to a .vue like this: <script src="./my-component.js"></script>
and <style src="./my-component.css"></style>
.
Contains all the markup structure and display logic of your component. Your template can contain any valid HTML, as well as some Vue-specific syntax.
v-if
directive renders the block if config
returns 'true'.
Contains all of the non-display logic of your component. Most importantly, your <script>
tag needs to have a default exported JS object. This object is where you locally register components, define component inputs (props), handle local state, define methods, and more. Your build step will process this object and transform it (with your template) into a Vue component with a render() function.
In the instance here defined data, methods, watchers, and props (inputs).
The first part of this block is the import of two objects from the helpers.js module (1).
export default{}
(2) is a component object, the .vue files` syntax that makes the following object definition available for use.
The data()
function (3) describes variables that we can use in the <template>
.
In the <template>
the widgetChangeHandler
method (4) is called on click (v-on
directive) to emit the value to the application that uses the button component.
Watchers 'spy' on one property of the component state, and run a function when that property value changes.
The props
block (6) defines variables, that are used in the Vue locally.
<style>
is where you write your CSS for the component. If you add a scoped attribute <style scoped>
Vue will scope the styles to the contents of your SFC. This works similar to CSS-in-JS solutions but allows you to just write plain CSS.
All the CSS is defined in the button-widget
class. If you want the widget field to occupy the entire cell on the dashboard - set width
and height
to 100%
. A user will be able to adjust the widget field in the previewer or on the dashboard. Also, choose the background
color.
Inside the button-widget
the button
appearance is nested:
Deeper in nesting:
medium
custom property defines minimal height and padding of the button.
contained
defines the button`s background-color
and the color on hover (again, nested in contained
).
The rest of the files - .html and .js - and icons subfolder are the same as in the .
The file with the Vue.js framework content. It is built in the one-file style - see below.
In the instance two Vue.js directives are used: v-if
- (see the), and v-on
- (see the ).
v-on
directive calls the widgetChangeHandler
method when a click happens. (See the block).
Styles for the widget are defined lower in the block of this file.
Then the block. Methods are closely interlinked to events because they are used as event handlers. Every time an event occurs, that method is called.
Watchers are defined in the block (5):
In the template project, the SCSS syntax is used to define the button's appearance (see ). You can have all the CSS in the <style> part of the .vue file, but in the template, this part is imported from a separate styles.scss file:
Here you can define the button text color, font-size, and others (see ).
Note that nested definition is made with underscores and a reference to the nested part of the style definition looks like button-widget__button
. See the block.
The first selector defines the cursor appearance over the button (See ).
Note how to call these nested definitions using the nesting path: button-widget__button--contained
. See the block.