富文本编辑器 CKEditor5 集成到自己的VUE项目里

集成方式

如果你跟我一样,在做vite构建的项目,那就集成来自在线构建器的构建方式。

而不是从源码构建,因为这种方式CKEditor官方对vite支持不太友好,bug频发,就别瞎折腾了,我是折腾过的...一言难尽...

→富文本编辑器CKEditor

CKEditor 5就是内嵌在网页中的一个富文本编辑器工具
CKEditor 5开发文档(英文):CKEditor 5 documentation

第一步:在线构建,定制好各种插件

到官网定制插件

官网定制

上面的目录结构,就是从CKEditor官网定制得到的,

 第二步:开始配置

 接下来,把这个文件夹,放到我们自己的项目的根目录中,这里文件夹起名为:ckeditor5,

随便什么名字都行,后面用的时候别写错了

我们需要两个依赖,上面这个,就是本地依赖了,在package.json中配置上:

"ckeditor5-custom-build": "file:ckeditor5"

key:起个名字就行。value:根目录里刚才放的文件夹名字

第二个依赖:

npm install @ckeditor/ckeditor5-vue

配置main.ts

import CkEditor from '@ckeditor/ckeditor5-vue'

app.use(CkEditor)

配置vite.config.ts

export default defineConfig({
  build: {
    commonjsOptions: {  
      exclude: ['ckeditor5-custom-build','ckeditor5/*'],
      include: []//这一行,如果是vite2.4版本,可以不加。到2.6就需要加上了
    },
  },
  optimizeDeps: {
    include: ['ckeditor5-custom-build/build/ckeditor'],
  },
  plugins: [
  ],
})

使用

新建一个vue文件,就能用了

<template>
    <ckeditor :editor="Editor" v-model="state.editorData" :config="state.editorConfig"></ckeditor>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
//导入自定义的pinia store
// import { useYiyaoStore } from '../pinia/yiyao.ts'
//导入解构方法
// import { storeToRefs } from 'pinia';
import  Editor  from 'ckeditor5-custom-build/build/ckeditor';

const state = reactive({
  editor: Editor,
  editorData: "<p>Content of the editor.</p>",
  editorConfig: {
    // The configuration of the editor.
  },
});

</script>

<style scoped>

</style>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值