huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame^] | 1 | <template> |
| 2 | <div> |
| 3 | <script id="editor" type="text/plain"></script> |
| 4 | </div> |
| 5 | </template> |
| 6 | <script> |
| 7 | export default { |
| 8 | name: 'UE', |
| 9 | data() { |
| 10 | return { |
| 11 | editor: null, |
| 12 | isReady: false, |
| 13 | isInit: false |
| 14 | } |
| 15 | }, |
| 16 | props: { |
| 17 | value: { |
| 18 | type: String |
| 19 | }, |
| 20 | config: { |
| 21 | type: Object |
| 22 | } |
| 23 | }, |
| 24 | mounted() { |
| 25 | const _this = this |
| 26 | window.UE.delEditor('editor') |
| 27 | this.editor = window.UE.getEditor('editor', this.config) // 初始化UE |
| 28 | // this.editor.addListener('ready', function() { |
| 29 | // _this.editor.setContent(_this.defaultMsg) // 确保UE加载完成后,放入内容。 |
| 30 | // }) |
| 31 | this.editor.ready(() => { |
| 32 | _this.setContent(_this.value) // 确保UE加载完成后,放入内容。 |
| 33 | _this.editor.addListener('contentChange', () => { |
| 34 | const content = _this.editor.getContent() |
| 35 | _this.$emit('input', content) |
| 36 | }) |
| 37 | |
| 38 | _this.$emit('ready', this.editor) |
| 39 | _this.isReady = true |
| 40 | }) |
| 41 | }, |
| 42 | methods: { |
| 43 | setContent(value) { |
| 44 | this.editor.setContent(value || '') |
| 45 | }, |
| 46 | getUEContent() { // 获取内容方法 |
| 47 | return this.editor.getContent() |
| 48 | } |
| 49 | }, |
| 50 | watch: { |
| 51 | value(val) { |
| 52 | this.setContent(val) |
| 53 | } |
| 54 | }, |
| 55 | destroyed() { |
| 56 | this.editor.destroy() |
| 57 | } |
| 58 | } |
| 59 | </script> |
| 60 | <style> |
| 61 | .edui-editor-toolbarbox{ |
| 62 | line-height:22px |
| 63 | } |
| 64 | </style> |