一、安装
npm install @tinymce/tinymce-vue -S

二、封装建一个组件

<template><div><Editorapi-key="xxxxx"tinymceScriptSrc="/tinymce/tinymce.min.js":init="{language: 'zh_CN',height: 500,paste_data_images: true, // 允许粘贴图像paste_webkit_styles: 'all',automatic_uploads: true,convert_urls: false,image_caption: true,content_style: `*{margin:0;padding:0;}body{font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, Helvetica,Segoe UI, Arial, Roboto, PingFang SC, miui, Hiragino Sans GB,Microsoft Yahei, sans-serif !important;}h1,h2,h3,h4,h5,h6,h7{font-size: 18px;}p,font{font-size: 16px;font-weight: 400;color: #262626;line-height: 24px;text-align: justify;word-break: break-all;letter-spacing: 1.5px;}p{text-indent:0;margin:0;}strong span{display: block;}div img,p img,img,span img{width:50% !important;height:auto;text-align:center;border-radius: 4px;display: block;margin: 15px auto 0 auto;}figcaption{text-align:center !important;margin: 20px 0 !important;}figure{margin: 0 auto !important;}`,toolbar: ['image media video bold fontsize forecolor backcolor italic underline strikethrough styleselect fontsizeselect alignleft aligncenter alignright alignjustify outdent indent lineheight cut copy outdent indent undo redo  blockquote table preview fullscreen',],menubar: false,branding: false,fontsize_formats: '11px 12px 14px 16px 17px 18px 24px 36px 48px',lineheight_formats: '10px 20px 30px 40px 50px 60px',imagetools_toolbar: 'imageoptions',file_picker_callback: file_picker_callback,paste_preprocess: paste_preprocess,init_instance_callback: init_instance_callback,images_upload_handler: example_image_upload_handle,urlconverter_callback: urlconverter_callback,}"v-model="content":plugins="['image', 'fullscreen', 'media', 'preview', 'paste']"@change="handleChange"></Editor></div>
</template>
<script lang="ts" setup>
import { ref, watch } from "vue";
import Editor from "@tinymce/tinymce-vue";
import { uploadFiles } from "@/utils/funtional";
import axios from "axios";
import { message } from "ant-design-vue";let props = defineProps<{readOnly?: boolean;value: string;
}>();let emits = defineEmits(["handleChange"]);let content = ref<string>();
let editorRef: any;watch(() => props.value,(val) => {content.value = val;},{deep: true,immediate: true,}
);
// 图片直接粘贴
const paste_preprocess = (_: any, args: Record<string, any>) => {if (args.content.indexOf("xiumi") !== -1) {return args.content;}const styleTag = /\s+style="[^"]*"/gi;args.content = args.content.replace(styleTag, () => {return "";}).replace(/(&nbsp;)|(<br>)|(<br\/>)/gi, () => {return "";});
};// 文件上传
const file_picker_callback = (callback: (key: string) => void,value: string,meta: Record<string, string>
) => {if (meta.filetype === "image") {if (!value) return;axios({url: value,method: "get",responseType: "arraybuffer",}).then((res) => {let code = btoa(new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte),""));let a = document.createElement("a");a.setAttribute("href", "data:image/png;base64," + code);a.download = "image" + new Date().getTime();a.click();a.remove();});}if (meta.filetype === "media") {let fileInput = document.createElement("input");fileInput.setAttribute("type", "file");fileInput.setAttribute("accept", ".mp4");fileInput.click();fileInput.addEventListener("change", async (e: any) => {let url = await uploadFiles(e.target.files[0]);callback(url);fileInput.remove();});}
};
// 图片上传
const example_image_upload_handle = async (blobInfo: Record<string, any>,success: (url: string) => void,failFun: (mes: string) => void
) => {let maxSize = blobInfo.blob().size / 1024 / 1024;if (maxSize > 10) {return failFun("请上传10M以内的图片");}let url = await uploadFiles(blobInfo.blob());success(url);
};const urlconverter_callback = (url: string) => {return url;
};const init_instance_callback = (ref: any) => {editorRef = ref;if (props.readOnly) {editorRef.setMode("readonly");}
};const handleChange = () => {emits("handleChange", content.value);
};
</script>

三、页面引入使用

<editor :value="value"/>

完成

注意:
用的时候偶尔会出现以下报错,服务器上找不到富文本插件的js,导致富文本加载不出来

解决办法:


里面找到

复制到

到官网去下来中文包,建一个langs的文件夹,放在里面(需要中文的情况)

然后页面引入

tinymceScriptSrc="/tinymce/tinymce.min.js"

这样富文本加载会变快,也不会出现找不到js文件的情况了

vue3 使用富文本tinymce-vue相关推荐

  1. vue使用富文本插件vue elemnt-tiptap和vue-quill-editor

    这两天由于项目要实现新闻发布的功能,所以上github和gitee找了一些项目,发现都是用富文本插件编译成html来实现功能.经过尝试和寻找,我使用了vue elemnt-tiptap和vue-qui ...

  2. Vue3使用富文本框(wangeditor)

    毕业涉及中使用到了富文本框,所以学习使用了wangeditor富文本框,现进行总结 1.安装 npm install @wangeditor/editor --savenpm install @wan ...

  3. vue3使用富文本编辑器wangEditor-v5(未使用composition api写法)

    效果 安装 安装核心库和其vue组件库 yarn add @wangeditor/editor yarn add @wangeditor/editor-for-vue@next 使用v-model封装 ...

  4. 【wangEditor富文本编辑器】富文本三种使用方法,html使用富文本,html套vue脚手架使用富文本,vue使用富文本【简单易用,复制即用】

    前言 富文本编辑器功能是很多人都要使用的 市面上有很多的编辑器可以供选择,但是很多编辑器会有点复杂,或者文档看起来难受. 我最近做了一个需求,是需要在html文件上写富文本编辑器. 但是我看了以前用的 ...

  5. vue3使用富文本编辑器vueQuill

    npm install @vueup/vue-quill@alpha --save 在main.js中引入 import { createApp } from 'vue' import { Quill ...

  6. vue获取编辑器纯文字_vue中使用富文本编辑器

    前端使用富文本编辑器的插件有很多,今天献上wangeditor的使用教程,教你如何在vue中使用富文本编辑器 wangeditor是一个萌新富文本编辑器,基于js和css,重点在于它轻量,如果你需要的 ...

  7. 学习日志day46(2021-09-10)(1、使用富文本编辑器simditor)

    学习内容:学习JavaWeb(Day46) 1.使用富文本编辑器simditor 1.使用富文本编辑器simditor (1)常见的富文本编辑器有simditor.CKEditor.tinymce.k ...

  8. Django 3.2.5博客开发教程:使用富文本编辑器添加数据

    在Django admin后台添加数据的时候,文章内容文本框想发布一篇图文并茂的文章需就得手写Html代码,这十分吃力,也没法上传图片和文件.这显然不是我等高大上程序猿想要的. 为提升效率,我们可以使 ...

  9. Django实现的博客系统中使用富文本编辑器ckeditor

    操作系统为OS X 10.9.2,Django为1.6.5. 1.下载和安装 1.1 安装 ckeditor 下载地址 https://github.com/shaunsephton/django-c ...

最新文章

  1. ccf 高速公路(顺便当tarjan模板)
  2. 如果现在只能用汇编和 Goto 编程......
  3. linux中操作java进程
  4. JSONObject.fromObject--JSON与对象的转换
  5. 一次难忘的产品发布经历
  6. 【pytorch】torch.nn.Identity()
  7. 小孔怎么用_奶粉罐我再也不扔了,在盖子上打几个孔放床边,全家人都抢着用...
  8. ElasticNet算法解析
  9. 操作系统银行家算法(课程设计报告)JAVA实现
  10. cookie被淘汰_可爱可恨的 Cookie
  11. 用selenium IDE编写自动化测试脚本
  12. IBM智慧商务 - IBM和SugarCRM携手提供全方位渠道客户体验
  13. Win10中英文切换 win键+空格
  14. 基于波动率模型对上证综指的建模与实证分析
  15. 用Python批量操作文件
  16. 训练3.21(CF 543B Destroying Roads)
  17. matlab最基础教程(四):常用的系统自带函数,符号变量与字符串篇
  18. 电脑开机直接进BIOS界面怎么办
  19. 小学生灯谜计算机,小学生谜语大全
  20. 软件测试——2022经济寒冬之下究竟还有没有出路?

热门文章

  1. Python 为什么list不能作为字典的key?
  2. SpringMVC ResponseBody返回字符串带双引号解决
  3. html js获取天气预报,js 读取天气预报信息 示例代码(百度地图天气接口)
  4. Unity热更新ToLua框架学习
  5. 解决联想拯救者显卡花屏
  6. 【高手分享:拼音/五笔输入法通用使用技巧】
  7. 【深度学习】Pytorch chunk函数
  8. 多读书,不如读好书:程序员必读的30本书
  9. [FAQ09811][NW]如何区分MNO和MVNO
  10. 零基础Unreal Engine 4(UE4)图文笔记之准备篇(一)