MigrationEditor.vue 1 KB
<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>