Element Tiptap Editor - 免费开源的 Vue 富文本编辑器,专门为搭配 Element UI 使用优化,使用很简单

Element Tiptap Editor - 免费开源的 Vue 富文本编辑器,专门为搭配 Element UI 使用优化,使用很简单

一款很容易上手配置的富文本编辑器,和 Element plus 一起使用效果非常好,还能自定义功能。

关于 Element Tiptap Editor

Element Tiptap Editor 是一个在 web 开发领域“所见即所得”的富文本编辑器,基于 tiptap 编辑器和 element-ui 开发,相比很多富文本编辑器,Element Tiptap Editor 使用易上手,对开发者友好,而且可扩展性强,设计简洁。

Element Tiptap Editor 官网

Element Tiptap Editor 的技术特性

  • 操作按钮等组件使用 element-ui 组件,整体样式协调美观
  • 有许多开箱即用的 extension(编辑器扩展)
  • 完美支持 markdown 语法
  • 支持 TypeScript
  • i18n 国际化支持(en, zh, pl, ru, de, ko, es, zh_tw, fr, pt_br, nl, he)
  • 高度自定义,可以自定义 extension 和它对应的菜单按钮视图
  • 操作灵活,可以通过直接控制编辑器的行为来定制编辑器
  • 提供中文文档

为什么选择 Element Tiptap Editor

上个月在项目的管理后台,接到到类似公告发布的需求,文字需要可以加强调色、列表编辑等较为轻量的富文本编辑需求,需要增加文章编辑的功能。

在一年多前我也写过文章推荐 Tiptap,这是一个基于 vue 的开源富文本编辑器,当时还是 1.x 版本,使用简单,现在更新的 2.0 全新版本,虽然功能更强大了,但复杂程度也大幅提升,1.x 版本也不再维护了。

就在一筹莫展的时候,发现了 Element Tiptap Editor,这是一个搭配 Element UI 使用,API 简化的 Tiptap 编辑器,在使用简单的同时,还能自定义扩展,一些需要按照一定格式插入或者格式化的内容,可以通过自定义扩展来完成,在 Element UI 搭建的项目中,Element Tiptap Editor 简直是最优的选择。

Element Tiptap Editor 气泡菜单

开发上手

Element Tiptap Editor 的官网很简洁,风格传承 Tiptap 1.x 版本,功能演示即代码,非常简单易懂。

当然也可以局部引入

富文本的操作菜单有很多,最简单的使用方法,就是配置需要用到的功能按钮,保持菜单的简洁,只要在按顺序把需要用到的功能罗列出来,传入组件,就完成了编辑器的搭建:

一个简单具备编辑功能的富文本编辑器就完成了。当然这些内置的功能都是基础的文字排版,如果要实现较为复杂的功能,比如插入特定结构或格式的内容(插入一篇文章的封面和摘要),原理是根据 Tiptap 提供的事件,将处理后的内容插入到文章的选中位置,官网有详细的文档,代码量很少,也很容易弄懂。

免费开源说明

Element Tiptap Editor 是一个免费开源的项目,基于 MIT 开源协议,而 Tiptap 和 Element UI 同样也是免费开源的。因此任何个人或者公司都可以免费下载使用,不管是个人项目还是商业项目,都可以免费使用。

Element Tiptap Editor 的官网不是很稳定,经常打不开,我们也可以直接访问它的 Github 主页:Leecason/element-tiptap

原文链接:https://www.thosefree.com/element-tiptap-editor

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Element UIvue-quill-editor富文本编辑器支持插入图片,但是默认的图片上传功能可能不能满足所有需求,需要进行自定义。 首先,在vue-quill-editor的配置中添加`imageHandler`方法,用于处理图片上传: ```javascript <template> <quill-editor v-model="content" :options="editorOption"></quill-editor> </template> <script> import { quillEditor } from 'vue-quill-editor' export default { components: { quillEditor }, data () { return { content: '', editorOption: { imageHandler: this.imageHandler // 添加imageHandler方法 } } }, methods: { imageHandler () { // 处理图片上传 } } } </script> ``` 然后,可以使用第三方上传组件(如`el-upload`)进行图片上传,上传完成后将图片地址返回给`quill-editor`。可以在`imageHandler`方法中实现该逻辑: ```javascript <template> <div> <el-upload class="upload-demo" :action="uploadUrl" :on-success="handleSuccess" :show-file-list="false" :headers="headers" ref="upload" > <el-button size="small" type="primary">上传图片</el-button> </el-upload> </div> </template> <script> import { quillEditor } from 'vue-quill-editor' import { mapGetters } from 'vuex' export default { components: { quillEditor }, data () { return { content: '', editorOption: { imageHandler: this.imageHandler }, uploadUrl: 'https://www.example.com/upload' // 图片上传地址 } }, computed: { ...mapGetters(['getToken']) // 获取token }, methods: { imageHandler () { const self = this const uploadImg = this.$refs.upload uploadImg.click() uploadImg.$refs.input.onchange = function () { const file = uploadImg.$refs.input.files[0] const formData = new FormData() formData.append('file', file) self.$axios.post(self.uploadUrl, formData, { headers: { 'Authorization': self.getToken // 设置token } }).then(res => { const url = res.data.url // 获取图片地址 const editor = self.$refs.editor.quill // 获取quill对象 const index = (editor.getSelection() || {}).index || editor.getLength() editor.insertEmbed(index, 'image', url) // 插入图片 }).catch(err => { console.log(err) }) } } } } </script> ``` 在这个例子中,使用了`el-upload`组件进行图片上传,上传完成后将图片地址返回给`quill-editor`。在`imageHandler`方法中,通过`this.$refs.editor.quill`获取到了`quill`对象,然后调用`insertEmbed`方法插入图片。 需要注意的是,由于`quill`对象是异步创建的,所以需要在`mounted`生命周期中获取到`quill`对象才能进行图片插入。可以使用`$nextTick`方法来确保获取到了`quill`对象: ```javascript <template> <quill-editor v-model="content" :options="editorOption" ref="editor"></quill-editor> </template> <script> import { quillEditor } from 'vue-quill-editor' export default { components: { quillEditor }, data () { return { content: '', editorOption: { imageHandler: this.imageHandler } } }, mounted () { this.$nextTick(() => { // 获取quill对象 const editor = this.$refs.editor.quill // 在quill对象中添加图片上传功能 editor.getModule('toolbar').addHandler('image', () => { this.$refs.upload.click() }) }) }, methods: { imageHandler () { // 处理图片上传 } } } </script> ``` 在这个例子中,通过`editor.getModule('toolbar').addHandler`方法,在`quill`对象中添加了一个`image`按钮,点击该按钮时触发了上传图片的逻辑。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值