Vue3 富文本编辑器插件wangEditor

news/2024/10/23 7:39:57/

先上Demo

最近笔者在Vue3开发过程中需要使用到富文本编辑器,最后找到这个插件,觉得挺不错,如果有开发者也有这样的需求,可以试试
先上demo:
在这里插入图片描述

在这里插入图片描述

Vue3使用方法

安装

yarn add @wangeditor/editor
# 或者 npm install @wangeditor/editor --saveyarn add @wangeditor/editor-for-vue@next
# 或者 npm install @wangeditor/editor-for-vue@next --save

使用

模板

<template><div style="border: 1px solid #ccc"><Toolbarstyle="border-bottom: 1px solid #ccc":editor="editorRef":defaultConfig="toolbarConfig":mode="mode"/><Editorstyle="height: 500px; overflow-y: hidden;"v-model="valueHtml":defaultConfig="editorConfig":mode="mode"@onCreated="handleCreated"/></div>
</template>

script

<script>
import '@wangeditor/editor/dist/css/style.css' // 引入 cssimport { onBeforeUnmount, ref, shallowRef, onMounted } from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'export default {components: { Editor, Toolbar },setup() {// 编辑器实例,必须用 shallowRefconst editorRef = shallowRef()// 内容 HTMLconst valueHtml = ref('<p>hello</p>')// 模拟 ajax 异步获取内容onMounted(() => {setTimeout(() => {valueHtml.value = '<p>模拟 Ajax 异步设置内容</p>'}, 1500)})const toolbarConfig = {}const editorConfig = { placeholder: '请输入内容...' }// 组件销毁时,也及时销毁编辑器onBeforeUnmount(() => {const editor = editorRef.valueif (editor == null) returneditor.destroy()})const handleCreated = (editor) => {editorRef.value = editor // 记录 editor 实例,重要!}return {editorRef,valueHtml,mode: 'default', // 或 'simple'toolbarConfig,editorConfig,handleCreated};}
}
</script> 

注意:

  • editorRef 必须用 shallowRef
  • 组件销毁时,要及时销毁编辑器

更多详细配置可见官网:官网地址


http://www.ppmy.cn/news/651682.html

相关文章

wangEditor的完整使用(二)

上一篇博客讲了wangEditor的使用&#xff0c;但是有一个问题就是在富文 本编辑器里编辑时不能看到文章的预览效果。 下面我来讲解下如何实现在编辑时也可以看到预览效果。 设置一个按钮 <div class"layui-inline layui-show-xs-block"><button type&quo…

wangEditor 富文本编辑器使用

wangEditor 富文本编辑器使用 框架&#xff1a; react hooks 链接: 官方文档参考 富文本编辑器组件 import wangeditor/editor/dist/css/style.css; // 引入 css import { useState, useEffect } from react; import { Editor, Toolbar } from wangeditor/editor-for-react;…

vue 中使用 wangeditor

项目中用到了富文本&#xff0c;选来选去选择了wangeditor,先写了demo&#xff0c;用起来还算比较简单 用法 安装 npm install wangeditor/editor --save npm install wangeditor/editor-for-vue --save 空白编辑器 <template><div id"app"><div…

wangEditor的使用及上传图片(一)

由于业务需要&#xff0c;最近新入手了一款富文本编辑器wangEditor&#xff0c;这是一款轻量级的富文本编辑器&#xff0c;比起百度的ueditor&#xff0c;这款编辑器的界面更加简单&#xff0c;文档也很详细。对于需求不是很高的功能来说&#xff0c;这款编辑器实在是不二之选。…

wangEditor的完整使用(一)

最近在做一个类似博客之类的页面&#xff0c;所以就打算借助wangEditor这一富文本编辑器来实现项目的需求。主要使用SpringBootJSPLayUi来完成。一.导入wangEditor.js 我自己使用的是wangEditor.min.js,通过手工导入的方式放在项目的静态文件下来引用。 下载地址&#xff1a;…

对wangeditor进行扩展---- 源代码

看到有人对我做的WangEditor比较感兴趣&#xff0c;问了一些问题。但由于我并不常来&#xff0c;所以就没能及时答复&#xff0c;抱歉了。 未避免以后类似问题发生&#xff0c;我将我修改的wangeditor.js直接发在这里&#xff0c;有兴趣的可以下载后自己分析。希望能帮到需要的…

vue 使用 wangeditor 富文本编辑器

wangeditor 是一个轻量级 web 富文本编辑器&#xff0c;配置方便&#xff0c;使用简单。 1&#xff09;安装 wangeditor 终端安装 wangeditor 库&#xff1a; yarn add wangeditor/editor # 或者 npm install wangeditor/editor --save2&#xff09;页面绑定 创建一个 xxx.…

【wangEditor 5】在线解析本地word,将内容展现在wangEditor中

最近有个问题&#xff0c;在word中复制的多张图片&#xff0c;或者同时复制了图片和文字&#xff0c;图片粘贴到编辑器中不显示。 原因很简单&#xff1a;浏览器无法直接访问本地资源下的文件&#xff0c;切记这一点&#xff0c;不要试图用浏览器直接访问你本地文件。因为从技…