最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Lifting Tiptap editor instance to Pinia store - Stack Overflow

programmeradmin0浏览0评论

I have a very basic tiptap editor setup in VueJS, something like this:

// TipTap.vue

<template>
  <div>
    <editor-content :editor="editor" spellcheck="false" />
  </div>
</template>
<script setup>
// Imports
const editor = ref(null)

onMounted(() => {
  editor.value = new Editor({
    editable: true,
    extensions: [
      StarterKit
    ],
    content: props.modelValue,
  })
})
</script>

And it works fine, but when I want to centralize my state in a Pinia store so that I'd be able to check editors state or call its' methods from different components, like so:

// editorStore.js

export const useEditorStore = defineStore('editor', () => {
  const editorRef = ref(null)
  const textEditorContent = ref('')

  const initializeEditor = () => {
    editorRef.value = new Editor({
      editable: true,
      extensions: [
        StarterKit
      ],
      content: textEditorContent.value,
    })
  }
})

<template>
  <div>
    <editor-content :editor="editor" spellcheck="false" />
  </div>
</template>
<script setup>

const editorStore = useEditorStore()
const editor = editorStore.editorRef
onMounted(() => {
  editorStore.initializeEditor()
})

It either breaks the reactivity

  • when using const editor = shallowRef(null) in the store

Or creates too much recursion

  • when using const editor = ref(null)

I feel like I am missing crucial logic when it comes to reactivity/state management here. What could be the problem?

发布评论

评论列表(0)

  1. 暂无评论