博客
关于我
VUE3(二十六)基于wangeditor自定义富文本插件
阅读量:397 次
发布时间:2019-03-05

本文共 2142 字,大约阅读时间需要 7 分钟。

wangeditor 组件使用指南

安装

安装wangeditor可以通过npm包管理工具完成。请在项目根目录下执行以下命令:

npm install wangeditor --save

组件代码

Wangeditor.vue

Wangeditor.ts

import { onMounted, onBeforeUnmount, ref, watch } from "vue";import WangEditor from "wangeditor";import hljs from "highlight.js";import { webScoketObject } from "@/hooks/common";export default {  name: "Wangeditor",  setup(props: any, content: any) {    const editor = ref();    let instance: any = '';    watch(      () => webScoketObject.is_click_send,      () => {        if (webScoketObject.is_click_send) {          instance.txt.clear();          webScoketObject.is_click_send = false;        }      }    );    onMounted(() => {      instance = new WangEditor(editor.value);      instance.config.languageType = [        "Bash", "C", "C#", "C++", "CSS", "Java", "JavaScript", "JSON",        "TypeScript", "Plain text", "Html", "XML", "SQL", "Go", "Kotlin",        "Lua", "Markdown", "PHP", "Python", "Shell Session", "Ruby", "typescript"      ];      instance.config.menus = [        "emoticon", "image", "code", "splitLine", "undo", "redo"      ];      instance.highlight = hljs;      instance.config.uploadImgServer = "/upload-img";      instance.config.uploadImgAccept = ["jpg", "jpeg", "png", "gif", "bmp"];      instance.config.uploadVideoServer = "/api/upload-video";      instance.config.height = 150;      instance.config.zIndex = 10;      instance.config.placeholder = "请输入您的文字!";      instance.config.colors = [        "#000000", "#eeece0", "#1c487f", "#4d80bf"      ];      instance.config.pasteIgnoreImg = true;      Object.assign(instance.config, {        onchange() {          content.emit("getWangEditorValue", instance.txt.html());        },        linkImgCallback(src: string) {          console.log("图片 src ", src);        },        onlineVideoCallback(video: string) {          console.log("插入视频内容", video);        }      });      instance.create();    });    onBeforeUnmount(() => {      instance.destroy();      instance = null;    });    return { editor };  }};

调用实例

在组件中使用wangeditor可以通过以下方式实现:

最终效果

wangeditor组件提供了一个功能强大的富文本编辑器,支持多种编程语言和格式化样式。通过上述配置,您可以轻松实现文本编辑、代码高亮、图片上传等功能。

转载地址:http://aqhwz.baihongyu.com/

你可能感兴趣的文章
【Bert101】变压器模型背后的复杂数学【02/4】
查看>>
Oracle面试题:Oracle中truncate和delete的区别
查看>>
ThreadLocal线程内部存储类
查看>>
thinkphp 常用SQL执行语句总结
查看>>
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
Tensorflow.python.framework.errors_impl.ResourceExhaustedError:无法分配内存[操作:AddV2]
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Symbolic Aggregate approXimation(SAX,符号聚合近似)介绍-ChatGPT4o作答
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
sum(a.YYSR) over (partition by a.hy_dm) 不需要像group by那样需要分组函数。方便。
查看>>
ORCHARD 是什么?
查看>>
Struts2中使用Session的两种方法
查看>>
Stream API:filter、map和flatMap 的用法
查看>>
STM32工作笔记0032---编写跑马灯实验---寄存器版本
查看>>
Static--用法介绍
查看>>
ssm旅游信息管理系统的设计与实现bus56(程序+开题)
查看>>
order by rand()
查看>>