浏览代码

tiptab editor > Update blog + toasted 토스트메세지사용법

김보경 5 年之前
父节点
当前提交
fa23de3b1c
共有 2 个文件被更改,包括 27 次插入0 次删除
  1. 14 0
      pages/instructor/blog/_id/edit.vue
  2. 13 0
      store/instructor/blog.js

+ 14 - 0
pages/instructor/blog/_id/edit.vue

@@ -50,6 +50,7 @@
       <div class="container">
         <editor
           @editorMounted="initBlogContent"
+          @editorUpdated="updateBlog"
         />
       </div>
     </div>
@@ -74,11 +75,24 @@ export default {
     await store.dispatch('instructor/blog/fetchBlogById', params.id)
   },
   methods: {
+    // initBlogContent(editor) {
+    //   if (this.blog && this.blog.content) {
+    //     editor.setContent(this.blog.content)
+    //   }
+    // }
     initBlogContent(initContent) {
       debugger
       if (this.blog && this.blog.content) {
         initContent(this.blog.content)
       }
+    },
+    async updateBlog(blogData) {
+      try{
+        await this.$store.dispatch('instructor/blog/updateBlog', {data: blogData, id: this.blog._id})
+        this.$toasted.success('Blog Updated!', {duration: 2000})
+      }catch(error){
+        this.$toasted.error('Blog cannot be saved!', {duration: 2000})
+      }
     }
   }
 }

+ 13 - 0
store/instructor/blog.js

@@ -24,6 +24,19 @@ export const actions = {
     } catch (error) {
       return error
     }
+  },
+  async updateBlog({commit, state}, {data, id}) {
+    try {
+      console.log('instructor/blog.js actions updateBlog call axios.$patch-> Id, data')
+      const blog = await this.$axios.$patch(`/api/v1/blogs/${id}`, data)
+      console.log('instructor/blog.js actions updateBlog done axios.$patch-> Id, data')
+      console.log('courses.js mutations call setBlog')
+      commit('setBlog', blog)
+      console.log('courses.js mutations done setBlog')
+      return state.item
+    } catch (error) {
+      return error
+    }
   }
 }