我将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构建,因为ons似乎有更多选择,并且更接近我的需求。但是documentation并没有告诉我如何毫无问题地将其集成到VueJS中。我尝试过,但是它似乎不想渲染,也没有错误消息告诉我我在做什么错。
有人知道如何在VueJS上下文中自定义CKeditor 5吗?该文档对VueJS的使用令人惊讶地轻巧。
答案 0 :(得分:0)
也碰到了这个问题。
经过研究,我发现您可以这样做:
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
// Somewhere in your code...
console.log(ClassicEditor.defaultConfig.toolbar);
希望这会有所帮助。