【发布时间】:2021-04-11 21:12:35
【问题描述】:
如何将自定义 CSS 类添加到元素 .ck-content,换句话说,添加到 CKEditor5 和 Vue2 中的可编辑格式化文本容器?
ck-content 是输入字段;我们必须将它与上面的工具栏、CKEditor 的其他部分区别开来。所以如果我们想应用一些只影响输入内容的类,它一定不能影响工具栏。
似乎是显而易见的解决方案:
<ckeditor class="CustomClass" :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
不会起作用,因为CustomClass 它不会应用于.ck-content,甚至不会应用于根元素。
下面的解决方案也不行,因为当CKEditorWrapper挂载时,CKEditor挂载还没有完成。
import CK_EditorVueAdaptation from "@ckeditor/ckeditor5-vue2";
@Component({
components: {
ckeditor: (CK_EditorVueAdaptation as { component: VueClass<unknown>; }).component
}
})
class CKEditorWrapper extends Vue {
private mounted(): void {
this.$el.getElementsByClassName("ck-content").item(0) // null
}
}
【问题讨论】:
-
こんにちは 一些想法:从文档中我看到组件有一些事件,要在不同阶段触发,例如this。您是否尝试过在@ready 事件处理程序中添加一个函数,并使用JavaScript 的
document.querySelector查找DOM 节点,然后添加您的自定义类? -
@マークさん,感谢您的评论!我想“准备好”就是答案。