-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRedactorX.vue
66 lines (61 loc) · 1.36 KB
/
RedactorX.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
<template>
<textarea ref="redactorx" :name="name" :placeholder="placeholder" />
</template>
<script>
export default {
props: {
modelValue: String,
placeholder: {
type: String,
default: null,
},
name: {
type: String,
default: null,
},
config: {
default: {},
type: Object,
},
},
mounted() {
this.init()
},
beforeDestroy() {
this.destroy()
},
methods: {
init() {
var me = this
var subscribe = {
"editor.change": function (event) {
var html = event.get("html")
me.handleInput(html)
return html
},
}
// extend config
if (typeof this.config.subscribe === "undefined") {
this.config.subscribe = subscribe
} else {
this.config.subscribe["editor.change"] = subscribe["editor.change"]
}
// call Redactor X
var app = RedactorX(this.$refs.redactorx, this.config)
// set instance
this.redactorx = app
this.$parent.redactorx = app
},
destroy() {
// Call destroy on redactor to cleanup event handlers
RedactorX(this.$refs.redactorx, "destroy")
// unset instance for garbage collection
this.redactorx = null
this.$parent.redactorx = null
},
handleInput(val) {
this.$emit("update:modelValue", val)
},
},
}
</script>