tiptap/packages/vue-3/src/useEditor.ts

18 lines
392 B
TypeScript
Raw Normal View History

import { onMounted, onBeforeUnmount, shallowRef } from 'vue'
2021-03-01 06:47:34 +08:00
import { EditorOptions } from '@tiptap/core'
import { Editor } from './Editor'
export const useEditor = (options: Partial<EditorOptions> = {}) => {
const editor = shallowRef<Editor>()
2021-03-01 06:47:34 +08:00
onMounted(() => {
editor.value = new Editor(options)
})
onBeforeUnmount(() => {
2021-03-18 04:21:57 +08:00
editor.value?.destroy()
2021-03-01 06:47:34 +08:00
})
return editor
}