Browse Source

rich text

xiongzhu 7 years ago
parent
commit
336b568625
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/main/vue/src/components/RichText.vue

+ 8 - 2
src/main/vue/src/components/RichText.vue

@@ -1,5 +1,5 @@
 <template>
-    <textarea id="tiny" v-model="content"></textarea>
+    <textarea v-model="content" ref="editor"></textarea>
 </template>
 <script>
     import axios from 'axios';
@@ -38,7 +38,7 @@
         },
         mounted() {
             tinymce.init({
-                selector: '#tiny',
+                target: this.$refs.editor,
                 skin_url: '/static/skins/lightgray',
                 language: 'zh_CN',
                 menubar: false,
@@ -68,6 +68,8 @@
                     })
                 },
                 init_instance_callback: editor => {
+                    this.editor = editor;
+                    this.editor.setContent(this.content);
                     editor.on('Change MouseOut', e => {
                         this.content = editor.getContent();
                     });
@@ -76,12 +78,16 @@
         },
         data() {
             return {
+                editor: null,
                 content: ''
             }
         },
         methods: {},
         watch: {
             value(val) {
+                if (this.editor) {
+                    this.editor.setContent(val);
+                }
                 this.content = val
             },
             content(val) {