Browse Source

tiptab editor 컨텐츠 초기화 > 컴포넌트간 함수 콜백 전달 방법

김보경 5 years ago
parent
commit
514df33168
2 changed files with 15 additions and 1 deletions
  1. 4 0
      components/editor/index.vue
  2. 11 1
      pages/instructor/blog/_id/edit.vue

+ 4 - 0
components/editor/index.vue

@@ -95,6 +95,7 @@ export default {
         })
       ]
     })
+    this.$emit('editorMounted', this.setInitialContent)
   },
   beforeDestroy(){
     // Always destroy your editor instance when it's no longer needed
@@ -113,6 +114,9 @@ export default {
       const node = nodes.find(n => n.type.name === name)
       if (!node) return ''
       return node.textContent
+    },
+    setInitialContent(content) {
+      this.editor.setContent(content)
     }
   }
 }

+ 11 - 1
pages/instructor/blog/_id/edit.vue

@@ -48,7 +48,9 @@
     </Header>
     <div class="blog-editor-container">
       <div class="container">
-        <editor/>
+        <editor
+          @editorMounted="initBlogContent"
+        />
       </div>
     </div>
   </div>
@@ -70,6 +72,14 @@ export default {
   },
   async fetch({params, store}){
     await store.dispatch('instructor/blog/fetchBlogById', params.id)
+  },
+  methods: {
+    initBlogContent(initContent) {
+      debugger
+      if (this.blog && this.blog.content) {
+        initContent(this.blog.content)
+      }
+    }
   }
 }
 </script>