Vue UI Components Documentation
Vue Editor Component
The Editor component for Vue represents a ready-for-use HTML text editor which can simplify web content creation or be a replacement of your HTML Text Areas.
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 Editor component for Vue requires the following import:
import JqxEditor from "jqwidgets-scripts/jqwidgets-vue/vue_jqxeditor.vue";
Add the jqxEditor component to the components section of the the Vue class:
components: { JqxEditor },
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 - <JqxEditor/>
<template> <JqxEditor :width="width" :height="height" :lineBreak="lineBreak"> <b>JqxEditor</b> is a HTML text editor designed to simplify web content creation. You can use it as a replacement of your Textarea. <br /> <br /> Features include: <br /> <ul> <li>Text formatting</li> <li>Text alignment</li> <li>Hyperlink dialog</li> <li>Image dialog</li> <li>Bulleted list</li> <li>Numbered list</li> </ul> </JqxEditor></template>
Properties
The properties of the <JqxEditor/> 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: 800, height: 400, lineBreak: 'div' }}
Events
The events in Vue are set as an attribute with @ prefix, for example:
<JqxEditor @change="onChange()" :width="width" :height="height" :lineBreak="lineBreak"> <b>JqxEditor</b> is a HTML text editor designed to simplify web content creation. You can use it as a replacement of your Textarea. <br /> <br /> Features include: <br /> <ul> <li>Text formatting</li> <li>Text alignment</li> <li>Hyperlink dialog</li> <li>Image dialog</li> <li>Bulleted list</li> <li>Numbered list</li> </ul></JqxEditor>
All events that are bound to a component are implemented in the methods
member of the Vue class.
methods: { onChange: 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:
<JqxEditor ref="editor"></JqxEditor>
Here how you can use a component's method:
this.$refs.editor.setMode(true);
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> <JqxEditor ref="editor" @change="onChange()" :width="width" :height="height" :lineBreak="lineBreak"> <b>JqxEditor</b> is a HTML text editor designed to simplify web content creation. You can use it as a replacement of your Textarea. <br /> <br /> Features include: <br /> <ul> <li>Text formatting</li> <li>Text alignment</li> <li>Hyperlink dialog</li> <li>Image dialog</li> <li>Bulleted list</li> <li>Numbered list</li> </ul> </JqxEditor></template> <script> // Import the components that will be used import JqxEditor from "jqwidgets-scripts/jqwidgets-vue/vue_jqxeditor.vue"; export default { components: { // Adding imported widgets here JqxEditor }, data: function () { // Define properties which will use in the widget return { width: 800, height: 400, lineBreak: 'div' } }, beforeCreate: function () { // Add here any data where you want to transform before components be rendered }, methods: { // Add here all used callbacks and/or events onChange: function () { // Do something... this.$refs.editor.setMode(true); } } }</script> <style></style>
Editor Example
<template> <JqxEditor :width="width" :height="400" :tools="tools" :createCommand="createCommand"> <b>JqxEditor</b> is a HTML text editor designed to simplify web content creation. You can use it as a replacement of your Textarea or you can create it from a DIV element. <br /> <br /> Features include: <br /> <ul> <li>Text formatting</li> <li>Text alignment</li> <li>Hyperlink dialog</li> <li>Image dialog</li> <li>Bulleted list</li> <li>Numbered list</li> </ul> </JqxEditor></template> <script> import JqxEditor from "jqwidgets-scripts/jqwidgets-vue/vue_jqxeditor.vue"; export default { components: { JqxEditor }, data: function () { return { width: 800, tools: 'bold italic underline | font size | left center right | outdent indent' } }, methods: { createCommand: function (name) { switch (name) { case 'font': return { init: (widget) => { widget.jqxDropDownList({ source: [ { label: 'Arial', value: 'Arial, Helvetica, sans-serif' }, { label: 'Comic Sans MS', value: '"Comic Sans MS", cursive, sans-serif' }, { label: 'Courier New', value: '"Courier New", Courier, monospace' }, { label: 'Georgia', value: 'Georgia,serif' }] }); } } case 'size': return { init: (widget) => { widget.jqxDropDownList({ source: [ { label: '8pt', value: 'xx-small' }, { label: '12pt', value: 'small' }, { label: '18pt', value: 'large' }, { label: '36pt', value: 'xx-large' } ] }); } } } } } }</script> <style></style>