javascript - Vue.js 的 ckeditor 组件中的 insertText()
问题描述
我正在尝试将ckeditor 5集成到我的 vue js 应用程序中。我已经成功添加了 ckeditor,但现在我想通过单击按钮在 ckeditor 的光标位置添加一些文本。所以为了实现这一点,我尝试了 insertText方法。但是在将代码添加为editor.model.change(...)时,我无法在 vue 中获取编辑器实例
Uncaught ReferenceError: editor is not defined
代码 =>
<template>
<ckeditor
id="custom"
ref="custom"
name="custom"
:editor="editor"
:config="editorCustomConfig"
v-model="message">
</ckeditor>
<a href="#" @click="addCodeInMsg">Add Text In Editor</a>
</template>
<script>
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
export default {
name: "topbar",
},
data() {
return {
editor: ClassicEditor,
editorConfig: {
},
message:''
};
},
methods: {
addCodeInMsg(e){
editor.change( writer => {
const insertPosition = editor.model.document.selection.getFirstPosition();
writer.insertText( 'CKEditor 5 rocks!', { linkHref: 'https://ckeditor.com/' }, insertPosition );
} );
}
}
</script>
我不知道我在使用 ckeditor 组件时缺少什么。任何帮助将不胜感激。
解决方案
当CKeditor准备好时,我可以通过你得到的编辑器对象来做到这一点。
在 on-ready-event 中,你会得到一个编辑器,然后我保存它以使用这些操作。
推荐阅读
- ios - 使用 UIRotationGestureRecognizer 将弧度转换为度数?
- reporting-services - 订阅状态:报告处理过程中发生错误
- c# - WPF 设计器 (xdesproc) 和 x64 目标
- visual-studio - Xbox UWP 内存快照崩溃
- python - 二叉树叶子值的总和
- sql-server - 如何在 SQLserver 中创建一个 SQL 过程以从不断增长的表列表中合并表
- r - 混淆矩阵错误:错误:`data`和`reference`应该是具有相同水平的因素
- rspec - capybara-screenshot 主机 URL 是否可配置?
- python-3.x - 使用 Grouper 的 pandas 系列日期时间索引中的月份名称
- jquery - .toggleclass / .addclass 不起作用 - 通过添加类“open”来激活下拉菜单