vue2 cli使用wangEditor ( wangEditor安装依赖, wangEditor.vue文件实例, wangEditor工具栏配置的key列表 )

news/2024/10/22 19:01:46/

 wangEditor官网地址https://www.wangeditor.com/

安装依赖

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

xxx.vue文件示例

<template><div style="border: 1px solid #ccc;"><Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig" :mode="mode" /><Editor style="height: 500px; overflow-y: hidden;" v-model="html" :defaultConfig="editorConfig" :mode="mode" @onCreated="onCreated" @onChange="onChange" /></div>
</template><script>
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { DomEditor } from "@wangeditor/editor";
export default {components: { Editor, Toolbar },data() {return {editor: null,html: '<p>hello</p>',toolbarConfig: {},editorConfig: { placeholder: '请输入内容...' },mode: 'default', // or 'simple'}},methods: {onCreated(editor) {this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错},onChange(editor) {const toolbar = DomEditor.getToolbar(editor);const curToolbarConfig = toolbar.getConfig();console.log(curToolbarConfig.toolbarKeys); // 当前菜单排序和分组},},mounted() {// 模拟 ajax 请求,异步渲染编辑器setTimeout(() => {this.html = '<p>模拟 Ajax 异步设置内容 HTML</p>'}, 1500)},beforeDestroy() {const editor = this.editorif (editor == null) returneditor.destroy() // 组件销毁时,及时销毁编辑器}
}
</script><style src="@wangeditor/editor/dist/css/style.css"></style>

 工具栏配置Key

["headerSelect",// 标题"blockquote", // 引用"bold", // 加粗"underline", // 下划线"italic", // 斜体// 删除线、清除格式等"group-more-style",{key: "group-more-style",title: "更多",iconSvg:'<svg viewBox="0 0 1024 1024"><path d="M204.8 505.6…0 153.6 0 76.8 76.8 0 1 0-153.6 0Z"></path></svg>',menuKeys: Array(5)},"color", // 文字颜色"bgColor", // 背景色"fontSize", // 字号"fontFamily", // 字体"lineHeight", // 行高"bulletedList", // 无序列表"numberedList", // 有序列表"todo", // 代办// 对齐"group-justify",{key: "group-justify",title: "对齐",iconSvg:'<svg viewBox="0 0 1024 1024"><path d="M768 793.6v1…72.8 102.4v102.4H51.2V102.4h921.6z"></path></svg>',menuKeys: Array(4)},// 缩进"group-indent",{key: "group-indent",title: "缩进",iconSvg:'<svg viewBox="0 0 1024 1024"><path d="M0 64h1024v1…32h1024v128H0z m0-128V320l256 192z"></path></svg>',menuKeys: Array(2)},"emotion",// 表情"insertLink",// 插入链接"group-image",// 上传图片{key: "group-image",title: "图片",iconSvg:'<svg viewBox="0 0 1024 1024"><path d="M959.877 128…l224.01-384 256 320h64l224.01-192z"></path></svg>',menuKeys: Array(2)},"group-video",// 上传视频{key: "group-video",title: "视频",iconSvg:'<svg viewBox="0 0 1024 1024"><path d="M981.184 160….904zM384 704V320l320 192-320 192z"></path></svg>',menuKeys: Array(2)},"insertTable",// 插入表格"codeBlock", // 代码块"divider", // 分割线"undo", // 撤销"redo", // 重做"fullScreen" // 全屏
]


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

相关文章

富文本编辑器wangEditor回显问题

回显时渲染dom报错问题&#xff1a; 富文本编辑器在回显html时偶尔会报以下错误&#xff1a; Error in v-on handler: "Error: Cannot find a descendant at path [1,1,0] in node: {“children”:[],“operations”:[{“type”:“remove_node”,“path”:[0],“node”:…

wangeditor安装

在没有搭建Vue-CLI的情况下安装wangeditor&#xff0c;官网原代码输入命令行后报错。 解决&#xff1a;把去掉&#xff0c;即可安装成功。 即输入npm install wangeditor --save

wangEditor介绍(入门级)

一、什么是富文本编辑器&#xff1f; 相信很多小伙伴都用过富文本编辑器。富文本编辑器&#xff08;Rich Text Editor&#xff0c;RTE&#xff09;是一种可内嵌于浏览器&#xff0c;所见即所得的文本编辑器。可以实现很多功能&#xff0c;如改变字体颜色&#xff0c;插入图片视…

vue使用wangEditor

vue中安装wangEditor npm install wangeditor创建公用组件&#xff1a;在src/components文件夹中创建wangEditor.vue <template lang"html"><div class"wangeditor"><div ref"toolbar" class"toolbar"></div&g…

【学习总结】wangeditor插件使用

之前的项目中就因为这个插件踩坑了&#xff0c;现在正好就用上这个插件了&#xff0c;相比最近使用的fullcalendar插件来说&#xff0c;wangeditor插件好用太多了&#xff08;"wangeditor/editor": "^5.0.0"&#xff09; 首先放上官网地址&#xff1a;点击…

WangEditor基本使用

WangEditor基本使用 效果图 1、使用到的API创建一个编辑器 https://www.kancloud.cn/wangfupeng/wangeditor3/335769获取内容 https://www.kancloud.cn/wangfupeng/wangeditor3/335775使用textarea https://www.kancloud.cn/wangfupeng/wangeditor3/430149上传图片到服务器 ht…

Alice语言介绍并推荐入门书籍(10本)

Alice是一种人工智能语言处理工具&#xff0c;旨在模拟人类对话并回答用户的问题。 这个语言处理工具基于人工智能技术&#xff0c;具有自然语言理解和生成的能力。它可以识别用户的语句&#xff0c;并尝试回答用户的问题或请求。Alice使用的算法可以根据用户输入的内容和上下…

富文本编辑器 wangeditor 的使用

富文本编辑器 wangeditor 的使用 为什么选择使用 wangeditor a. 轻量、简洁、界面美观、文档齐全、易用、开源免费、开源团队维护、有专业Q群答疑、持续更新、无需使用其他库。插件功能基本符合我们目前的业务需求 b. 相比较于TinyMCE一类的编辑器&#xff0c;中文文档入门简单…