当前位置: 首页 > news >正文

v2富文本框封装 @wangeditor/editor-for-vue

 1 组件封装

<template><div class="editor-container"><div class="editor-wrapper"><Toolbarstyle="border-bottom: 1px solid #ccc":editor="editor":defaultConfig="toolbarConfig":mode="mode"/><Editorstyle="height: 500px; overflow-y: hidden;"v-model="html":defaultConfig="editorConfig":mode="mode"@onCreated="handleCreated"@onChange="handleChange"/></div></div>
</template><script>
import '@wangeditor/editor/dist/css/style.css'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
// 下载包
// npm install @wangeditor/editor-for-vue
// npm install @wangeditor/editor
// npm install @wangeditor/plugin-upload-attachment // 上传附件插件// npm install @wangeditor/editor@v5.1.23
// npm install @wangeditor/editor-for-vue@1.0.2export default {name: 'MyEditor',components: { Editor, Toolbar },data() {return {editor: null,html: '<p>请输入内容...</p>',toolbarConfig: {},editorConfig: {placeholder: '请输入内容...',MENU_CONF: {uploadImage: {server: '/api/upload', // 替换为您的图片上传接口fieldName: 'file',maxFileSize: 10 * 1024 * 1024, // 10MBmaxNumberOfFiles: 10,allowedFileTypes: ['image/*'],customInsert(res, insertFn) {// res 即服务端的返回结果// 从 res 中找到图片 url 并插入insertFn(res.url)},onError(file, err, res) {console.error(`${file.name} 上传出错`, err, res)}}}},mode: 'default'}},methods: {handleCreated(editor) {this.editor = Object.seal(editor)},handleChange(editor) {this.$emit('update:content', editor.getHtml())}},beforeDestroy() {const editor = this.editorif (editor == null) returneditor.destroy()}
}
</script><style scoped>
.editor-container {width: 100%;margin: 20px auto;text-align: left;
}.editor-wrapper {border: 1px solid #ccc;margin: 0 20px;
}:deep(.w-e-text-container) {text-align: left;
}
</style> 

2 组件引入

<template><div class="wang-editor-page"><h2>WangEditor 富文本编辑器</h2><MyEditor @update:content="handleContentChange"/></div>
</template><script>
import MyEditor from '../components/MyEditor.vue'export default {name: 'WangEditor',components: {MyEditor},methods: {handleContentChange(content) {console.log('编辑器内容更新:', content)}}
}
</script><style scoped>
.wang-editor-page {padding: 20px;
}h2 {text-align: center;margin-bottom: 20px;
}
</style> 

http://www.lryc.cn/news/523420.html

相关文章:

  • 【分类】【损失函数】处理类别不平衡:CEFL 和 CEFL2 损失函数的实现与应用
  • AUTOSAR从入门到精通-自动驾驶测试技术
  • 优化大型语言模型的表达能力和依赖关系:理论
  • 在Ubuntu下使用Wine运行MobaXterm并解决X服务器问题
  • 【鸿蒙】0x02-LiteOS-M基于Qemu RISC-V运行
  • SW - 钣金零件保存成DWG时,需要将折弯线去掉
  • JAVA使用自定义注解,在项目中实现EXCEL文件的导出
  • 【GIS操作】使用ArcGIS Pro进行海图的地理配准(附:墨卡托投影对比解析)
  • flutter在使用gradle时的加速
  • ABP - 缓存模块(1)
  • 二、点灯基础实验
  • 双端队列实战 实现滑动窗口 用LinkedList的基类双端队列Deque实现 洛谷[P1886]
  • HTML<img>标签
  • 【网络 MAC 学习专栏 -- 如何理解 PHY 的 Link Up】
  • Linux虚拟机安装与FinalShell使用:探索Linux世界的便捷之旅
  • Mixly米思齐1.0 2.0 3.0 软件windows版本MAC苹果电脑系统安装使用常见问题与解决
  • vben5 admin ant design vue如何使用时间范围组件RangePicker
  • Kafka 日志存储 — 文件目录及日志格式
  • 故障诊断 | BWO白鲸算法优化KELM故障诊断(Matlab)
  • 一文读懂AI Agent 智能体
  • 《 C++ 点滴漫谈: 二十二 》操作符炼金术:用C++ operator重塑代码美学
  • 通信协议之多摩川编码器协议
  • 新星杯-ESP32智能硬件开发--ESP32的I/O组成-系统中断矩阵
  • 4329 树的连边II
  • Spring的Bean详解=Bean别名+作用范围+使用场景
  • 聊一聊如何适应AI时代
  • dl学习笔记:(4)简单神经网络
  • 电商项目高级篇08-springCache
  • 4.1 AI 大模型应用最佳实践:如何提升 GPT 模型使用效率与质量
  • Linux top命令cpu使用率计算底层原理