-
Notifications
You must be signed in to change notification settings - Fork 80
/
Editor.vue
67 lines (58 loc) · 1.64 KB
/
Editor.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<textarea :id="id" ref="editor"></textarea>
</template>
<script>
export default {
name: 'p-editor',
props: {
value: String,
options: Object,
id: {
type: String,
default: 'editor'
}
},
mounted () {
if (!window.tinymce) {
return
}
let options = Object.assign({}, {
selector: `#${this.id}`,
height: 500,
language: 'zh_CN',
plugins: [
'advlist autolink lists link image charmap print preview anchor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code'
],
toolbar: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image'
}, this.options)
const editor = this.editor = tinymce.EditorManager.createEditor(this.id, options)
editor.on('change keyup nodechange', (e) => {
const val = editor.getContent()
this.$emit('change', val)
this.$emit('input', val)
this.$parent.$emit('el.form.change', val)
})
editor.on('blur', (e) => {
this.$emit('blur', e)
this.$parent.$emit('el.form.blur', editor.getContent())
})
editor.on('init', (e) => {
editor.setContent(this.value)
})
editor.render()
},
methods: {
setContent (val) {
this.editor.setContent(val)
},
getContent () {
this.editor.getContent()
}
},
beforeDestory () {
tinymce && tinymce.execCommand('mceRemoveEditor', false, this.id)
}
}
</script>