Skip to content

Commit 6a8a02f

Browse files
committed
refine tinymce
1 parent d56cd59 commit 6a8a02f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/components/Tinymce/index.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class='tinymce-container editor-container'>
3-
<textarea class='tinymce-textarea' :id="id"></textarea>
3+
<textarea class='tinymce-textarea' :id="tinymceId"></textarea>
44
<div class="editor-custom-btn-container">
55
<editorImage color="#20a0ff" class="editor-upload-btn" @successCBK="imageSuccessCBK"></editorImage>
66
</div>
@@ -15,8 +15,7 @@ export default {
1515
components: { editorImage },
1616
props: {
1717
id: {
18-
type: String,
19-
default: 'tinymceEditor'
18+
type: String
2019
},
2120
value: {
2221
type: String,
@@ -29,12 +28,6 @@ export default {
2928
return ['removeformat undo redo | bullist numlist | outdent indent | forecolor | fullscreen code', 'bold italic blockquote | h2 p media link | alignleft aligncenter alignright']
3029
}
3130
},
32-
data() {
33-
return {
34-
hasChange: false,
35-
hasInit: false
36-
}
37-
},
3831
menubar: {
3932
default: ''
4033
},
@@ -44,6 +37,13 @@ export default {
4437
default: 360
4538
}
4639
},
40+
data() {
41+
return {
42+
hasChange: false,
43+
hasInit: false,
44+
tinymceId: this.id || 'vue-tinymce-' + +new Date()
45+
}
46+
},
4747
watch: {
4848
value(val) {
4949
if (!this.hasChange && this.hasInit) {
@@ -54,7 +54,7 @@ export default {
5454
mounted() {
5555
const _this = this
5656
window.tinymce.init({
57-
selector: `#${this.id}`,
57+
selector: `#${this.tinymceId}`,
5858
height: this.height,
5959
body_class: 'panel-body ',
6060
object_resizing: false,
@@ -153,12 +153,12 @@ export default {
153153
imageSuccessCBK(arr) {
154154
const _this = this
155155
arr.forEach(v => {
156-
window.tinymce.get(_this.id).insertContent(`<img class="wscnph" src="${v.url}" >`)
156+
window.tinymce.get(_this.tinymceId).insertContent(`<img class="wscnph" src="${v.url}" >`)
157157
})
158158
}
159159
},
160160
destroyed() {
161-
window.tinymce.get(this.id).destroy()
161+
window.tinymce.get(this.tinymceId).destroy()
162162
}
163163
}
164164
</script>

src/views/components/tinymce.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="components-container">
33
<code>公司做的后台主要是一个cms系统,公司也是以自媒体为核心的,所以富文本是后台很核心的功能。在选择富文本的过程中也走了不少的弯路,市面上常见的富文本都基本用过了,最终选择了Tinymce<a target='_blank' href='https://segmentfault.com/a/1190000009762198#articleHeader13'> 相关文章 </a> <a target='_blank' href='https://www.tinymce.com/'> 官网 </a></code>
44
<div>
5-
<tinymce :height=200 ref="editor" v-model="content"></tinymce>
5+
<tinymce :height='200' v-model="content"></tinymce>
66
</div>
77
<div class='editor-content' v-html='content'></div>
88
</div>

0 commit comments

Comments
 (0)