vue 中使用 wangeditor

news/2024/10/23 9:36:33/

项目中用到了富文本,选来选去选择了wangeditor,先写了demo,用起来还算比较简单

用法

安装

npm install @wangeditor/editor --save
npm install @wangeditor/editor-for-vue --save

空白编辑器

<template><div id="app"><div style="border: 1px solid #ccc;"><Toolbarstyle="border-bottom: 1px solid #ccc":editor="editor":defaultConfig="toolbarConfig":mode="mode"/><Editorstyle="height: 500px; overflow-y: hidden;"v-model="html"@onChange="lisChange($event)":defaultConfig="editorConfig":mode="mode"@onCreated="onCreated"/></div></div>
</template><script>import '@wangeditor/editor/dist/css/style.css'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'export default({components: { Editor, Toolbar },data() {return {editor: null,html: '<p>hello</p>',toolbarConfig: { },editorConfig: { placeholder: '请输入内容...' },mode: 'simple', // or 'simple'}},methods: {onCreated(editor) {this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错},lisChange(e){console.log(e.getHtml())}},mounted() {},beforeDestroy() {const editor = this.editorif (editor == null) returneditor.destroy() // 组件销毁时,及时销毁编辑器}
})
</script><style></style>

其他用到的配置

菜单不显示某个按钮

toolbarConfig: {excludeKeys: ['fullScreen',//不显示全屏'insertVideo',//不显示插入视频]},

上传图片

editorConfig: {placeholder: '请输入内容...',MENU_CONF: {// 配置上传图片uploadImage: {customUpload: this.uploadImageMe // this.uploadImageMe 是 methods 中的一个普通方法},}},
//上传文件配置uploadImageMe(file, insertFn){// file 即选中的文件// 自己实现上传,并得到图片 url alt hreflet name = file.name;let suffix = file.type.split("/")[1];name = name + '.' + suffix;let formdata = new FormData()formdata.append("file", file)  //上传方法uploadImg(formdata).then(res => {// 最后插入图片insertFn(res.url , res.name, res.url )})},

还有就是上传视频,但是我的版本比较低(应该是v4.6.3 开始支持上传本地视频) ,只能上传网络视频

这个的话,就比较鸡肋了,所以放弃了这个功能

其他API

判断是否为空

this.editor.isEmpty() 

有标签就不算空,所以我判断是否为空用的是

this.editor.getText()=='' //this.editor.getText() 获取纯文本

 获取toolbar所有key

this.editor.getAllMenuKeys()


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

相关文章

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;不要试图用浏览器直接访问你本地文件。因为从技…

wangEditor富文本编辑器获取html内容

该示例为官方示例&#xff0c;代码仅供参考。 功能&#xff1a;获取html内容&#xff0c;目录结构如下&#xff1a; get-html.html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta http-equiv"X-UA…

vue 使用wangEditor

1、npm install wangeditor/core wangeditor/editor wangeditor/editor-for-vue 2、封装组件 MyEditor.vue, &#xff08;这里是通过props content 将展示内容传入&#xff09; <template><div><div style"border: 1px solid #ccc; margin-top: 10px&quo…

vue2使用wangEditor

vue2使用wangEditor 前几天一个月薪35k的兄弟&#xff0c;给我推了一个人工智能学习网站&#xff0c;看了一段时间挺有意思的。包括语音识别、机器翻译等从基础到实战都有&#xff0c;很详细&#xff0c;分享给大家。大家及时保存&#xff0c;说不定啥时候就没了。 效果 wang…