5 changed files with 48 additions and 56 deletions
@ -1,61 +1,47 @@ |
|||
<template> |
|||
<div id="editorSection"></div> |
|||
<template lang="html"> |
|||
<div> |
|||
<!-- id="editor1"对应挂载方式EditorInit1 --> |
|||
<!-- <div style="color:black;" id="editor1"></div> --> |
|||
<!-- ref="editor2"对应挂载方式EditorInit2 --> |
|||
<div style="color:black;text-align: left;" ref="editor2"></div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import Editor from "tui-editor"; /* ES6 */ |
|||
import "tui-editor/dist/tui-editor.css"; // editor's ui |
|||
import "tui-editor/dist/tui-editor-contents.css"; // editor's content |
|||
import "codemirror/lib/codemirror.css"; // codemirror |
|||
import "highlight.js/styles/github.css"; // code block highlight |
|||
import { init } from "echarts/lib/echarts"; |
|||
import E from 'wangeditor' |
|||
export default { |
|||
methods:{ |
|||
// WangEditor两种挂载方法,一种挂在id(EditorInit1),一种挂在ref(EditorInit2) |
|||
EditorInit1(){ |
|||
const editor1 = new E ('#editor1'); |
|||
editor1.create(); |
|||
}, |
|||
EditorInit2(){ |
|||
const temp = this.$refs.editor2; |
|||
const editor2 = new E (temp); |
|||
editor2.create(); |
|||
}, |
|||
mounted(){ |
|||
//记得在生命周期mounted中加上咱们写的函数,这里用EditorInit1或是EditorInit2都可以 |
|||
this.EditorInit2(); |
|||
}, |
|||
|
|||
export default { |
|||
props:{ |
|||
content:{ |
|||
type: String, |
|||
default: '' |
|||
} |
|||
}, |
|||
watch: { |
|||
content(val){ |
|||
if(val){ |
|||
this.setValue(val) |
|||
} |
|||
} |
|||
}, |
|||
mounted() { |
|||
this.initialize(); |
|||
this.$nextTick(() => { |
|||
this.setValue(this.content) |
|||
}) |
|||
}, |
|||
beforeDestroy() { |
|||
this.tuieditor = null; |
|||
delete this.tuieditor; |
|||
}, |
|||
methods: { |
|||
initialize() { |
|||
if (this.$el) { |
|||
this.tuieditor = new Editor({ |
|||
el: document.querySelector("#editorSection"), |
|||
initialEditType: "wysiwyg", |
|||
previewStyle: "vertical", |
|||
height: "800px", |
|||
}); |
|||
this.tuieditor.getHtml(); |
|||
} |
|||
}, |
|||
|
|||
getValue() { |
|||
return this.tuieditor.getHtml() |
|||
}, |
|||
setValue(val) { |
|||
this.tuieditor.setHtml(val); |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
</script> |
|||
|
|||
<style> |
|||
<style lang="css"> |
|||
.editor { |
|||
width: 100%; |
|||
margin: 0 auto; |
|||
position: relative; |
|||
z-index: 0; |
|||
} |
|||
.toolbar { |
|||
border: 1px solid #ccc; |
|||
} |
|||
.text { |
|||
border: 1px solid #ccc; |
|||
min-height: 500px; |
|||
} |
|||
</style> |
|||
|
Loading…
Reference in new issue