CourseEditor.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="editor course-editor">
  3. <course-menu :editor="editor"/>
  4. <editor-content
  5. class="editor__content"
  6. :editor="editor"
  7. />
  8. </div>
  9. </template>
  10. <script>
  11. import { Editor, EditorContent } from 'tiptap'
  12. import CourseMenu from '~/components/editor/CourseMenu'
  13. import {
  14. Bold,
  15. Italic,
  16. History,
  17. OrderedList,
  18. BulletList,
  19. ListItem,
  20. } from 'tiptap-extensions'
  21. export default {
  22. components: {
  23. EditorContent, CourseMenu
  24. },
  25. props: {
  26. initialContent: {
  27. required: true,
  28. type: String
  29. }
  30. },
  31. data() {
  32. return {
  33. editor: null
  34. }
  35. },
  36. // This is called only on client (in browser)
  37. mounted() {
  38. this.editor = new Editor({
  39. extensions: [
  40. new Bold(),
  41. new Italic(),
  42. new History(),
  43. new OrderedList(),
  44. new BulletList(),
  45. new ListItem()
  46. ]
  47. })
  48. this.initialContent && this.editor.setContent(this.initialContent)
  49. },
  50. beforeDestroy() {
  51. this.editor && this.editor.destroy()
  52. }
  53. }
  54. </script>
  55. <style lang="scss">
  56. .course-editor {
  57. * {
  58. &:focus {
  59. outline: none;
  60. }
  61. }
  62. border: 1px solid gray;
  63. .editor__content {
  64. padding: 0 20px 20px 20px;
  65. }
  66. }
  67. </style>