tinymce 官方为 vue 项目提供了一个组件 tinymce-vue

一、安装tinymce-vue

npm install @tinymce/tinymce-vue -S

二、下载tinymce

npm install tinymce -S

下载的时候可以先在static(public)下面建个目录tinymce,下载tinymce完成后在node_modules 中找到 tinymce/skins目录,将其复制到static\tinymce目录下面

三、下载中文语言包

https://www.tiny.cloud/get-tiny/language-packages/

下载完成后将其解压到public\tinymce目录下面,最终目录结构形式如下

四、创建组件tinymce.vue

<template>
<div class="tinymce-editor">
<editor v-model = "myValue" :init="init" :disabled="disabled" @onClick="onClick"></editor>
</div>
</template>
<script>
// import axios from "axios";
import tinymce from "tinymce/tinymce";
import Editor from "@tinymce/tinymce-vue";
import "tinymce/themes/silver";
// 编辑器插件plugins
// 更多插件参考:https://www.tiny.cloud/docs/plugins/
import "tinymce/plugins/image"; // 插入上传图片插件
// import 'tinymce/plugins/media'// 插入视频插件
import "tinymce/plugins/table"; // 插入表格插件
import "tinymce/plugins/lists"; // 列表插件
import "tinymce/plugins/wordcount"; // 字数统计插件
export default {
components: {
Editor
},
props: {
value: {
type: String,
default: ""
},
// 基本路径,默认为空根目录,如果你的项目发布后的地址为目录形式,
// 即abc.com/tinymce,baseUrl需要配置成tinymce,不然发布后资源会找不到
baseUrl: {
type: String,
default: ""
},
disabled: {
type: Boolean,
default: false
},
plugins: {
type: [String, Array],
default: "lists image table wordcount"
},
// 在toolbar中添加工具栏相应按钮
toolbar: {
type: [String, Array],
default:
"undo redo | formatselect | bold italic forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists image table | removeformat"
}
},
data() {
return {
init: {
language_url: `${this.baseUrl}/tinymce/langs/zh_CN.js`, // 语言包路径
language: "zh_CN", //语言
skin_url: `${this.baseUrl}/tinymce/skins/ui/oxide`, //skin路径
content_css: `${this.baseUrl}/tinymce/skins/content/default/content.css`,
// skin_url: `${this.baseUrl}/tinymce/skins/ui/oxide-dark`, // 暗色系
// content_css: `${this.baseUrl}/tinymce/skins/content/dark/content.css`, // 暗色系
height: 300, //编辑器高度
plugins: this.plugins,
toolbar: this.toolbar,
branding: false, //是否禁用“Powered by TinyMCE”
menubar: false, //顶部菜单栏显示
// 此处为图片上传处理函数
// 如需ajax上传可参考https://www.tiny.cloud/docs/configure/file-image-upload/#images_upload_handler
// images_upload_handler: (blobInfo, success, failure) => {
// let formdata = new FormData()
// formdata.set('file', blobInfo.blob())
// axios.post(url, formdata).then(res => {
// success(res.data.data)
// }).catch(res => {
// failure('error')
// })
// },
},
myValue: this.value
};
},
mounted() {
tinymce.init({});
},
methods: {
// 添加相关的事件,可用的事件参照文档=> https://github.com/tinymce/tinymce-vue => All available events
// 需要什么事件可以自己增加
onClick(e) {
this.$emit("onClick", e, tinymce);
},
// 可以添加一些自己的自定义事件,如清空内容
clear() {
this.myValue = "";
}
},
watch: {
value(newValue) {
this.myValue = newValue;
},
myValue(newValue) {
this.$emit("input", newValue);
}
}
};
</script>

 五、引入组件

<template>
<div>
<tinymce-editor ref="editor" v-model="value"></tinymce-editor>
</div>
</template> <script>
import tinymceEditor from "./tinymce.vue";
export default {
data() {
return {
value: ""
};
},
components: {
tinymceEditor
}
};
</script>

效果图如下

移动端处理富文本参数(图片、长串字母)

        let obj = res.data;    // 假如该参数为富文本内容
obj.content = obj.content.replace(/<img/g, "<img width='100%'")  
obj.content = obj.content.replace(/[\s;]width:.+?/gi, '')
obj.content = obj.content.replace(/<img[^>]*?(src="[^"]*?")[^>]*?>/g, '<img $1/>')
obj.content = obj.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto"')
obj.content = obj.content.replace(/<p/g, "<p style='word-wrap:break-word'")

Vue tinymce富文本编辑器的更多相关文章

  1. vue项目富文本编辑器vue-quill-editor之自定义图片上传

    使用富文本编辑器的第一步肯定是先安装依赖 npm i vue-quill-editor 1.如果按照官网富文本编辑器中的图片上传是将图片转为base64格式的,如果需要上传图片到自己的服务器,需要修改 ...

  2. 在 Vue 项目中引入 tinymce 富文本编辑器

    项目中原本使用的富文本编辑器是 wangEditor,这是一个很轻量.简洁编辑器 但是公司的业务升级,想要一个功能更全面的编辑器,我找了好久,目前常见的编辑器有这些: UEditor:百度前端的开源项 ...

  3. vue中引入Tinymce富文本编辑器

    最近想在项目上引入一个富文本编辑器,之前引入过summernote,感觉并不太适合vue使用, 然后在网上查了查,vue中使用Tinymce比较适合, 首先,我们在vue项目的components文件 ...

  4. Vue集成tinymce富文本编辑器并实现本地化指南(2019.11.21最新)

     tinymce是一款综合口碑特别好.功能异常强大的富文本编辑器,在某些网站,甚至享有"宇宙最强富文本编辑器"的称号.那么,在Vue项目中如何集成呢?这并不困难,只需要参照官方教程 ...

  5. tinymce 富文本编辑器 编写资料

    tinymce官方文档: 粘贴图片插件 博客搬运地址 使用Blob获取图片并二进制显示实例页面 tinymce自动调整插件 是时候掌握一个富文本编辑器了——TinyMCE(1) XMLHttpRequ ...

  6. Django使用tinymce富文本编辑器

    1 - 安装 pip install django-tinymce==2.6.0 2 - 注册app INSTALLED_APPS = ( ... 'tinymce', ) 3 - 在setting中 ...

  7. tinymce富文本编辑器整合到django

    第一步:定义表存图片路径 models.py class AdminIMG(models.Model):     filename = models.CharField(max_length=200, ...

  8. vue集成百度UEditor富文本编辑器

    在前端开发的项目中.难免会遇到需要在页面上集成一个富文本编辑器.那么.如果你有这个需求.希望可以帮助到你 vue是前端开发者所追捧的框架,简单易上手,但是基于vue的富文本编辑器大多数太过于精简.于是 ...

  9. 前端vue-TinyMCE富文本编辑器表情插件报错解决

    最近项目中需要使用文本编辑器,比较了下最终选择了TinyMCE这款富文本编辑器.我安装的是TinyMCE v5但是在使用表情插件的时候,表情一直都出不来,报错信息如下: Uncaught Syntax ...

随机推荐

  1. Digital Twin 数字孪生

    GE的一个NB视频:http://v.youku.com/v_show/id_XMjk0NTMzODIyNA==.html http://www.gongkong.com/news/201701/35 ...

  2. FakeLogonScreen抓取Windows凭证

    FakeLogonScreen抓取Windows凭证 实践中使用的配置 攻击者: 操作系统: Kali Linux 2020.1 IP: 192.168.1.13 目标: 作业系统: Windows ...

  3. CCS过渡和动画

    过渡 过渡能让使用过渡的元素在样式发生变化时(例如鼠标划过,单击按钮,点击图片时,颜色,尺寸,位置等样式发生变化),定义变化过程中的动画,让变化不再是瞬间产生. 过渡样式使用transition定义, ...

  4. 前端html,css考点

    1, 内联元素,块级元素相关知识点 参考链接:https://edu.aliyun.com/a/103378 (1)置换元素 概念:浏览器根据元素的标签和属性,来决定元素的具体显示内容.<img ...

  5. javascript30--day03--Css Variables

     相关视频链接:https://www.bilibili.com/video/av8481988/?p=5 相关github地址:https://github.com/soyaine/JavaScri ...

  6. 字符串转数字 (With C++)

    1.stoi().stof().stod() 实现字符串转 int.float.double. stoi -> string to integer stof -> string to fl ...

  7. Invalid `Podfile` file: undefined method `pod' for main:Object.

    如果你是在iOS中引用flutter的时候,报的这个错.建议移步 https://www.cnblogs.com/jukaiit/p/12181184.html 其他: 先 "pod set ...

  8. LoaderTest加载测试用例的方法总结

    加载用例,可以用suite.addTest(测试类名("测试函数名"))实现,也可用过suit.addTest(loader.Loader....)实现,一下针对Loader的三个 ...

  9. Mac下appium-doctor提示错误汇总

    一.            提示 [Error: Could not detect Mac OS X Version from sw_vers output: '10.12'] 解决方法: 1.终端执 ...

  10. linux cpp (接口与实现的分离)

    以下是 .h 文件,是接口. 以下是函数的实现 以下是主函数 首先是以上两个文件编译,不用编译头文件 g++ -c gradeBook.cpp g++ -c gradeBook.main.cpp 之后 ...