MigrationEditor.vue
1 KB
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
<template>
<div ref="editor" class="migration-editor" />
</template>
<script>
export default {
name: "MigrationEditor",
props: {
value: { type: String, default: "" },
disabled: { type: Boolean, default: false },
},
data() {
return { editor: null };
},
watch: {
value(value) {
if (this.editor && value !== this.editor.txt.html()) {
this.editor.txt.html(value || "");
}
},
disabled(value) {
if (!this.editor) {
return;
}
value ? this.editor.disable() : this.editor.enable();
},
},
mounted() {
const Editor = require("wangeditor");
this.editor = new Editor(this.$refs.editor);
this.editor.config.zIndex = 100;
this.editor.config.onchange = html => this.$emit("input", html);
this.editor.create();
this.editor.txt.html(this.value || "");
if (this.disabled) {
this.editor.disable();
}
},
beforeDestroy() {
if (this.editor) {
this.editor.destroy();
}
this.editor = null;
},
};
</script>
<style scoped>
.migration-editor {
min-height: 320px;
}
</style>