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
| <template>
| <div>
| <script :id="randomId" type="text/plain" style="height: 300px;"></script>
| </div>
| </template>
|
| <script>
|
| export default {
| name: 'UE',
| props: {
| value: {
| default: function () {
| return ''
| }
| }
| },
| data () {
| return {
| randomId: 'editor_' + Math.random() * 100000000000000000,
| // 编辑器实例
| instance: null,
| ready: false
| }
| },
| watch: {
| value: function (val, oldVal) {
| if (val != null && this.ready) {
| // eslint-disable-next-line no-undef
| this.instance = UE.getEditor(this.randomId)
| this.instance.setContent(val)
| }
| }
| },
| mounted () {
| this.initEditor()
| },
|
| beforeDestroy () {
| if (this.instance !== null && this.instance.destroy) {
| this.instance.destroy()
| }
| },
| methods: {
| initEditor () {
| this.$nextTick(() => {
| // eslint-disable-next-line no-undef
| this.instance = UE.getEditor(this.randomId)
| this.instance.addListener('ready', () => {
| this.ready = true
| this.$emit('ready', this.instance)
| })
| })
| },
| getUEContent () {
| return this.instance.getContent()
| },
| setText (con) {
| // eslint-disable-next-line no-undef
| this.instance = UE.getEditor(this.randomId)
| this.instance.setContent(con)
| }
| }
| }
| </script>
|
|