gpt4 book ai didi

javascript - 如何在 VueJS 应用程序中自定义 CKEditor 5

转载 作者:行者123 更新时间:2023-11-30 06:17:01 29 4
gpt4 key购买 nike

我集成了 CKeditor 5 for VueJS进入我的 VueJS 应用:

<template>
<div :class="[columnClass, errors[name] ? 'has-danger' : '']" class="form-group">
<ckeditor :id="name"
:readonly="readonly"
:disabled="disabled"
:editor="editor"
:config="editorConfig"
:value="value"
class="form-control"
@input="$emit('input', $event)"/>
<small class="form-control-feedback">
<span v-for="e in errors[name]" :key="e">{{ e }}</span>
</small>
</div>
</template>

<script>

import BaseInput from './BaseInput';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

export default {
name: 'TextEditor',
extends: BaseInput,
props: {
value: {
type: String,
default: ''
},
},
data() {
return {
editor: ClassicEditor,
editorConfig: {
toolbar: [ 'bold', 'italic', 'underline', 'strikethrough', 'subscript', 'superscript', '|', 'headings', '|', 'undo', 'redo' ],
heading: {
options: [
{model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph'},
{model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1'},
{model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2'},
{model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3'},
{model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4'}
]
}
}
};
},
};
</script>

这很好用。

现在我想自定义显示的工具栏,我已经尝试了一些自定义配置,但并不奏效。我的工具栏中只显示粗体、斜体、重做和撤消。在我看来,CKeditor 让这有点困难,而且文档也很奇怪。

根据documentation我必须运行 Array.from( editor.ui.componentFactory.names() ); 来获取可能的工具栏选项列表,因为它取决于其他因素我的构建中可用的选项,那里没有可用的中央专用列表。这也意味着我不知道我想禁用的选项是如何调用的。

那个方法在VueJS中当然不行。我无法获得工具栏选项的列表。 我如何在 VueJS 中检索此选项列表?无法从 this.ClassicEditor 检索它,并且它在 Vue DevTools 中也不可见。在我看来,ui.componentFactory.names 在 VueJS 中并不容易获得。

除此之外,我可能必须使用 documentation 中描述的方法添加缺少的额外功能,例如下划线、上标。 ,而且我不知道如何在 VueJS 上下文中执行此操作。

我还尝试使用 Documenteditor 构建,而不是 Classical 构建,因为它似乎有更多选择,并且更接近我的需要。但是 documentation没有告诉我如何毫无问题地将它集成到 VueJS 中。我试过了,但它似乎不想渲染,也没有显示任何错误消息来告诉我我做错了什么。

有人知道如何在 VueJS 上下文中自定义 CKeditor 5 吗?该文档对 VueJS 的用法出奇地简洁。

最佳答案

刚好也遇到了这个问题。

经过一些研究,我发现你可以这样做:

import ClassicEditor from '@ckeditor/ckeditor5-build-classic';

// Somewhere in your code...
console.log(ClassicEditor.defaultConfig.toolbar);

希望这对您有所帮助。

关于javascript - 如何在 VueJS 应用程序中自定义 CKEditor 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55531854/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com