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

富文本编辑组件封装,tinymce、tinymce-vue

依赖:package.json

yarn add tinymce @tinymce/tinymce-vue

{"dependencies": {"@tinymce/tinymce-vue": "5.0.0","tinymce": "6.3.1","vue": "3.2.45",},
}

本地依赖:

在public下创建 static/tinymce 文件夹,包含

1:langs(中文语言包,官方下载地址)

2:skins(皮肤,从 node_modules/tinymce/skins 中复制)

 

组件封装:com-editor/index.vue

<template><div><editor v-model="content" :init="init" :disabled="disabled"></editor></div>
</template><script>
import tinymce from "tinymce/tinymce";
import Editor from "@tinymce/tinymce-vue";
import "tinymce/models/dom";
import "tinymce/themes/silver/theme";
import "tinymce/icons/default/icons";
import "tinymce/plugins/link"; //链接
import "tinymce/plugins/code"; //源代码
import "tinymce/plugins/codesample"; //代码示例
import "tinymce/plugins/wordcount"; //字数统计
import "tinymce/plugins/table"; //表格
import "tinymce/plugins/lists"; //列表(无序、有序)
import "tinymce/plugins/advlist"; //增强列表
import "tinymce/plugins/emoticons"; //字符表情
import "tinymce/plugins/emoticons/js/emojiimages";
import "tinymce/plugins/emoticons/js/emojis";
import "tinymce/plugins/preview"; //预览
import "tinymce/plugins/fullscreen"; //全屏
import "tinymce/plugins/image"; //图片
import "tinymce/plugins/searchreplace"; //查找替换
export default {components: {Editor,},props: {modelValue: {type: String,default: "",},disabled: {type: Boolean,default: false,},height: {type: Number,default: 500,},},data() {return {//初始化配置init: {branding: false, //不显示右下角富文本支持方menubar: false, //不显示菜单栏statusbar: false, //不显示底部状态栏language_url: "/static/tinymce/langs/zh-Hans.js", //汉化language: "zh-Hans",skin_url: "/static/tinymce/skins/ui/tinymce-5", //主题content_css: "/static/tinymce/skins/content/default/content.css", //样式font_size_formats: "12px 14px 16px 18px 24px 36px 48px 56px 72px", //字号font_family_formats:"微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;", //字体height: this.height, //高度plugins: "",toolbar: "",// tinymce插入图片支持转base64操作images_upload_handler: (blobInfo, progress) => {return new Promise((resolve, reject) => {resolve("data:" + blobInfo.blob().type + ";base64," + blobInfo.base64());});},},content: this.modelValue,plugins: {lists: "列表",advlist: "列表增强",link: "链接",table: "表格",code: "源代码",codesample: "代码示例",wordcount: "字数统计",image: "图片",emoticons: "表情",preview: "预览",fullscreen: "全屏",searchreplace: "查找替换",},toolbar: {undo: "回退",redo: "前进","removeformat |": "清除格式",// styles: "样式",blocks: "段落",fontsize: "字号",// fontfamily: "字体",bold: "加粗",italic: "斜体",strikethrough: "删除","underline |": "下划线",forecolor: "字体颜色","backcolor |": "背景颜色",alignleft: "左对齐",aligncenter: "居中对齐",alignright: "右对齐",alignjustify: "两端对齐",bullist: "无序列表",numlist: "有序列表",outdent: "减少缩进",indent: "增加缩进","lineheight |": "行高",link: "链接",blockquote: "引用",hr: "分割线",emoticons: "表情",image: "图片",table: "表格","codesample |": "代码块",wordcount: "字数统计",code: "源代码",preview: "预览",fullscreen: "全屏",searchreplace: "查找替换",},menubar: {// file:'文件',edit: "编辑",view: "查看",insert: "插入",format: "格式",tools: "工具",table: "表格",},};},created() {// this.init.menubar = Object.keys(this.menubar).join(" "); //菜单栏this.init.plugins = Object.keys(this.plugins).join(" "); //插件依赖this.init.toolbar = Object.keys(this.toolbar).join(" "); //插件栏tinymce.init({});},methods: {},watch: {modelValue(newValue) {this.content = newValue;},content(newValue) {this.$emit("update:modelValue", newValue);},},
};
</script>
<style lang="scss">
//不展示右侧升级链接
.tox-promotion {display: none;
}
</style>

组件使用:com-editor/demo.vue

<template><div>com-editor Demo<div>{{ content }}</div><com-editor v-model="content"></com-editor></div>
</template><script>
export default {components: {},data() {return {content: "<p>dddddd</p>",};},methods: {},
};
</script><style scoped></style>

使用效果:

参考链接:

vue项目中使用 tinymce 富文本(本地依赖版)

tinymce官方文档

tinymce个人中文文档

Migrating from TinyMCE 5

inymce使用images_upload_handler将图片处理成base64或者url

tinymce6 上传图片报错Cannot read properties of undefined (reading ‘then‘)

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

相关文章:

  • 电子作业指导书系统能树立良好的生产形象
  • Doris单机部署
  • 利用身份证号获取生日信息
  • c++模板的简单认识
  • 真香!Linux 原来是这么管理内存的
  • 计网之IP协议和以太网
  • 华为OD机试 - 关联子串(Python) | 机试题+算法思路+考点+代码解析 【2023】
  • SpringBoot学习笔记(二)
  • 亚马逊云科技SageMaker:实现自动、可视化管理迭代
  • 汽车 Automotive > CAN Transceivers收发器选择
  • AI将如何影响程序员的未来,以及如何不被AI所替代。
  • nginx 常用配置之 pass_proxy
  • Linux中驱动模块加载方法分析
  • yarn 通过 resolutions,指定子孙依赖包版本号,解决froala-editor 版本问题
  • Elasticsearch7.8.0版本进阶——多文档操作流程
  • Scala函数式编程(第五章:函数基础、函数高级详解)
  • ZED相机快速使用指南
  • 树莓派4b配置OpenWrt联网
  • 不同语言下的定时器,你都掌握了吗?
  • 华为OD机试 - 水仙花数(Python) | 机试题+算法思路+考点+代码解析 【2023】
  • 在onBindViewHolder设置View的translation失败或错乱的问题
  • 【2.21】MySQL索引、动态规划、学习方法
  • 华为OD机试题 - 二叉树层次遍历(JavaScript)| 包含代码编写思路
  • 力扣解法汇总1140. 石子游戏 II
  • Kerberos认证原理与使用教程
  • 内存取证常见例题思路方法-volatility (没有最全 只有更全)
  • 10 种主数据模型设计示例分享,推荐收藏
  • React学习笔记
  • 【Vue源码解析】Vue虚拟dom和diff算法
  • 算法学习与填充计划---2023.2.21---夏目