-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCkeditor.vue
45 lines (43 loc) · 944 Bytes
/
Ckeditor.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<template>
<textarea id="editor" :value="value"
v-on:input="updateValue($event.target.value)" >
</textarea>
</template>
<script>
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
export default {
name: 'Ckeditor',
data: function () {
return {
instance: null
}
},
props: ['value'],
watch: {
value () {
let html = this.instance.getData()
if (html !== this.value) {
this.instance.setData(this.value)
}
}
},
mounted () {
ClassicEditor
.create(this.$el, {
toolbar: ['bold', 'italic', 'link', 'bulletedList']
})
.then(editor => {
this.instance = editor
editor.model.document.on(change, () => { this.updateValue(editor.getData()) })
})
.catch(error => {
console.error(error)
})
},
methods: {
updateValue: function (value) {
this.$emit('input', value)
}
}
}
</script>