博客
关于我
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/

你可能感兴趣的文章
NSURLSession下载和断点续传
查看>>
NSUserdefault读书笔记
查看>>
NS图绘制工具推荐
查看>>
NT AUTHORITY\NETWORK SERVICE 权限问题
查看>>
NT symbols are incorrect, please fix symbols
查看>>
ntelliJ IDEA 报错:找不到包或者找不到符号
查看>>
NTFS文件权限管理实战
查看>>
ntko web firefox跨浏览器插件_深度比较:2019年6个最好的跨浏览器测试工具
查看>>
ntko文件存取错误_苹果推送 macOS 10.15.4:iCloud 云盘文件夹共享终于来了
查看>>
ntp server 用法小结
查看>>
ntpdate 通过外网同步时间
查看>>
ntpdate同步配置文件调整详解
查看>>
NTPD使用/etc/ntp.conf配置时钟同步详解
查看>>
NTP及Chrony时间同步服务设置
查看>>
NTP服务器
查看>>
NTP配置
查看>>
NUC1077 Humble Numbers【数学计算+打表】
查看>>
NuGet Gallery 开源项目快速入门指南
查看>>
NuGet(微软.NET开发平台的软件包管理工具)在VisualStudio中的安装的使用
查看>>
nuget.org 无法加载源 https://api.nuget.org/v3/index.json 的服务索引
查看>>