CKEditor 5 不适用于 Vue 3 Composition API

发布于 2025-01-11 09:15:09 字数 488 浏览 0 评论 0原文

我尝试在本地使用 CKEditor 和 vue 3 组合 api,但编辑器未显示在页面上 这里可能是组件

<template>
    <PageWrapper title="Post">
        <CKEditor :editor="editor"></CKEditor>
    </PageWrapper>
</template>


<script setup>
import PageWrapper from '@/components/PageWrapper.vue'
import CKEditor from '@ckeditor/ckeditor5-vue'
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'

const editor = ClassicEditor
</script>

出了什么问题?

I am trying to use CKEditor with vue 3 composition api locally but the editor not shown on the page
here is may component

<template>
    <PageWrapper title="Post">
        <CKEditor :editor="editor"></CKEditor>
    </PageWrapper>
</template>


<script setup>
import PageWrapper from '@/components/PageWrapper.vue'
import CKEditor from '@ckeditor/ckeditor5-vue'
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'

const editor = ClassicEditor
</script>

What's wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

救赎№ 2025-01-18 09:15:09

来自官方 文档非常简单,使用脚本设置,我发现它可以这样工作



    
    import CKEditor from '@ckeditor/ckeditor5-vue'
    import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
    
    const editor = ClassicEditor
    const ckeditor = CKEditor.component


然后就可以正常使用模板中的组件了。

From the official documentation it's pretty straightforward, using script setup, i found it working this way



    
    import CKEditor from '@ckeditor/ckeditor5-vue'
    import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
    
    const editor = ClassicEditor
    const ckeditor = CKEditor.component


then you can use the component in the template properly.

咋地 2025-01-18 09:15:09
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
import {reactive}    from 'vue'

export default {
    setup() {
        let editor = reactive(ClassicEditor);
        return {editor}
    }
}
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
import {reactive}    from 'vue'

export default {
    setup() {
        let editor = reactive(ClassicEditor);
        return {editor}
    }
}
谎言月老 2025-01-18 09:15:09
import CKEditor from '@ckeditor/ckeditor5-vue';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
export default {
  components: {
    ckeditor: CKEditor.component
  },
  data() {
    return {
      editor: ClassicEditor,
      editorConfig: {
        
      }
    }
  }

然后在模板内

  <ckeditor :editor="editor" v-model="youModel" :config="editorConfig"></ckeditor>

完美运行

import CKEditor from '@ckeditor/ckeditor5-vue';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
export default {
  components: {
    ckeditor: CKEditor.component
  },
  data() {
    return {
      editor: ClassicEditor,
      editorConfig: {
        
      }
    }
  }

then inside template

  <ckeditor :editor="editor" v-model="youModel" :config="editorConfig"></ckeditor>

Works perfectly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文