市面上众多富文本编辑器
quill
、wangEditor
、Tinymce
、ckEditor
等等,这里感觉ckEditor最为丝滑~。
文章
- 安装
- 安装vue组件相关以及富文本类型
- 其他富文本类型
- 新建CkEditor5组件
- 使用
安装
安装vue组件相关以及富文本类型
复制代码
1
2npm install --save @ckeditor/ckeditor5-vue2
复制代码
1
2npm install --save @ckeditor/ckeditor5-build-classic
其他富文本类型
类型预览
复制代码
1
2npm install --save @ckeditor/ckeditor5-build-inline
复制代码
1
2npm install --save @ckeditor/ckeditor5-build-balloon
复制代码
1
2npm install --save @ckeditor/ckeditor5-build-balloon-block
复制代码
1
2npm install --save @ckeditor/ckeditor5-build-decoupled-document
新建CkEditor5组件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54<template> <div> <ckeditor :editor="editor" :value="content" :disabled="disabled" @input="onEditorInput" :config="editorConfig" ></ckeditor> </div> </template> <script> import CKEditor from "@ckeditor/ckeditor5-vue2"; import ClassicEditor from "@ckeditor/ckeditor5-build-classic"; import "@ckeditor/ckeditor5-build-classic/build/translations/zh-cn"; export default { name: "CkEditor5", components: { ckeditor: CKEditor.component }, data() { return { editor: ClassicEditor, editorConfig: { language: "zh-cn" } }; }, model: { prop: "content", event: "updateContent" }, props: { // 文本 content: { type: String, default: "" }, // 是否禁用 disabled: { type: Boolean, default: false } }, methods: { onEditorInput(val) { this.$emit("updateContent", val); } } }; </script>
使用
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32<template> <div> <ck-editor v-model="test" :disabled="disabled"></ck-editor> <el-button @click="getData">获取绑定数据</el-button> <el-button @click="setDisabeld">设置是否禁用</el-button> </div> </template> <script> import ckEditor from "@/components/ckeditor/Ckeditor5"; export default { name: "Home", components: { ckEditor }, data() { return { test: "test", disabled: false }; }, methods: { getData() { console.log(this.test); }, setDisabeld() { this.disabled = !this.disabled; } } }; </script>
效果
1.赋值:
2.禁用
至于其他的插件和Toolbar、图片上传等等直接参考官网进行设置即可。
是不是感觉特简单,可惜的是CKEditor5
并没有去兼容iE11
.
ckeditor5兼容说明
所以就要说到CKEditor4
了。下文富文本vue集成 CKEditor4的简单封装
千里之行
始于足下
最后
以上就是彪壮老虎最近收集整理的关于富文本vue集成 CKEditor5的简单封装的全部内容,更多相关富文本vue集成内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复