This is Vue component wrapping TOAST UI Editor.
npm install --save @toast-ui/vue-editor
TOAST UI products are available over the CDN powered by TOAST Cloud.
You can use the CDN as below.
<script src="https://uicdn.toast.com/toast-ui.vue-editor/latest/vue-editor.js"></script>
If you want to more details, see Tutorials π
-
Using module
If you use some kind of bundle loader like
webpack
ofrollup
, you can add the import like this:// es modules import { Editor } from '@toast-ui/vue-editor' // commonjs require var ToustUI = require('@toast-ui/vue-editor'); // you can use toastui.Editor
-
Using only Vue wrapper component
vue-eidtor.js
has all of the tui.editor. If you only need vue wrapper component, you can use@toast-ui/vue-editor/src/index.js
like this:import { Editor } from '@toast-ui/vue-editor/src/index'
-
Using
<script>
If you just add javascript file to your html, you use CDN or
vue-editor.js
downloaded. Insert<script>
in your html like this:<script src="path/to/vue-editor.js"></script>
First implement <tui-editor>
in the template.
<template>
<tui-editor/>
</template>
And then add Editor
to the components
in your component or Vue instance like this:
import { Editor } from '@toast-ui/vue-editor'
export default {
components: {
'tui-editor': Editor
}
}
or
import { Editor } from '@toast-ui/vue-editor'
new Vue({
el: '#app',
components: {
'tui-editor': Editor
}
});
If you use v-model, you have to declare a data
for binding.
In the example below, editorText
is binding to the text of the editor.
<template>
<tui-editor v-model="editorText"/>
</template>
<script>
import { Editor } from '@toast-ui/vue-editor'
export default {
components: {
'tui-editor': Editor
},
data() {
return {
editorText: ''
}
}
}
</script>
Name | Type | Default | Description |
---|---|---|---|
value | String | '' | This prop can change content of the editor. If you using v-model , don't use it. |
options | Object | following defaultOptions |
Options of tui.editor. This is for initailize tui.editor. |
height | String | '300px' | This prop can control the height of the editor. |
previewStyle | String | 'tab' | This prop can change preview style of the editor. (tab or vertical ) |
mode | String | 'markdown' | This prop can change mode of the editor. (markdown or wysiwyg ) |
html | String | - | If you want change content of the editor using html format, use this prop. |
visible | Boolean | true | This prop can control visible of the eiditor. |
const defaultOptions = {
minHeight: '200px',
language: 'en_US',
useCommandShortcut: true,
useDefaultHTMLSanitizer: true,
usageStatistics: true,
hideModeSwitch: false,
toolbarItems: [
'heading',
'bold',
'italic',
'strike',
'divider',
'hr',
'quote',
'divider',
'ul',
'ol',
'task',
'indent',
'outdent',
'divider',
'table',
'image',
'link',
'divider',
'code',
'codeblock'
]
};
- load : It would be emitted when editor fully load
- change : It would be emitted when content changed
- stateChange : It would be emitted when format change by cursor position
- focus : It would be emitted when editor get focus
- blur : It would be emitted when editor loose focus
If you want to more manipulate the Editor, you can use invoke
method to call the method of tui.editor. For more information of method, see method of tui.editor.
First, you need to assign ref
attribute of <tui-editor/>
and then you can use invoke
method through this.$refs
like this:
<template>
<tui-editor ref="tuiEditor"/>
</template>
<script>
import { Editor } from '@toast-ui/vue-editor'
export default {
components: {
'tui-editor': Editor
},
methods: {
scroll() {
this.$refs.tuiEditor.invoke('scrollTop', 10);
},
moveTop() {
this.$refs.tuiEditor.invoke('moveCursorToStart');
},
getHtml() {
let html = this.$refs.tuiEditor.invoke('getHtml');
}
}
};
</script>
TOAST UI products are open source, so you can create a pull request(PR) after you fix issues. Run npm scripts and develop yourself with the following process.
Fork develop
branch into your personal repository.
Clone it to local computer. Install node modules.
Before starting development, you should check to haveany errors.
$ git clone https://github.com/{your-personal-repo}/[[repo name]].git
$ cd [[repo name]]
$ npm install
Let's start development!
Before PR, check to test lastly and then check any errors. If it has no error, commit and then push it!
For more information on PR's step, please see links of Contributing section.