安装Tinymce

现在tinymce-vue最新版本是4.0,用的vue3.0的了,所以搭建的vue2.0项目要使用之前的版本 ( 安装指定版本 ).

首先安装tinymce的vue组件,因为没有注册服务:

npm install @tinymce/tinymce-vue@2.0.0 -S

接着安装tinymce:

npm install tinymce@5.0.3 -S

当然也可以安装其他版本的.

我的vue2.0项目一开始直接使用以下命令安装最新版的tinymce, 然后报错了. 如果是vue3项目的话, 应该可以这么安装.

npm install @tinymce/tinymce-vue -S
npm install tinymce -S

下载中文包

tinymce是英文的,所以需要从官网下载中文包:
地址: https://www.tiny.cloud/get-tiny/language-packages/

配置

在 public 文件夹下新建一个 tinymce 的文件夹, 用来存放tinymce的文件.

tinymce 文件夹中新建一个 langs 文件夹用来放语言包,
再从 node_modules 中复制 skins 文件夹, 放到tinymce 文件夹下.

注意 node_modules 文件夹中有两个与tinymce 有关的文件夹, 一个是 @tinymce, 一个是 tinymce, 不要搞错了

icons 是显示富文本框的图标用的, 没有 icons 这个文件夹的朋友, 可以直接从其他地方复制一份.

<百度网盘> – 整个tinymce文件夹的压缩包
链接:https://pan.baidu.com/s/1ADkod4auWdwEFhXy9ndIjg
提取码:nrq1

icons 中的结构如图:

使用tinymce

首先要写一个tinymce的组件, 然后再将这个组件引入

tinymce组件 (仅作为参考)

以下代码中, 图片部分可用, 视频部分不可用.

<template><div><div class="tinymce-box"><!--      <el-button @click="clickHandler">上传视频</el-button>--><Editorv-model="contentValue":init="init":disabled="disabled"@onClick="onClick"/></div></div>
</template><script>
//引入tinymce编辑器
import Editor from "@tinymce/tinymce-vue";//引入node_modules里的tinymce相关文件文件
import tinymce from "tinymce/tinymce"; //tinymce默认hidden,不引入则不显示编辑器
import "tinymce/themes/silver"; //编辑器主题,不引入则报错
import "tinymce/icons/default"; //引入编辑器图标icon,不引入则不显示对应图标// 引入编辑器插件(基本免费插件都在这儿了)
import "tinymce/icons/default/icons";
import "tinymce/plugins/advlist"; //高级列表
import "tinymce/plugins/anchor"; //锚点
import "tinymce/plugins/autolink"; //自动链接
import "tinymce/plugins/autoresize"; //编辑器高度自适应,注:plugins里引入此插件时,Init里设置的height将失效
import "tinymce/plugins/autosave"; //自动存稿
import "tinymce/plugins/charmap"; //特殊字符
import "tinymce/plugins/code"; //编辑源码
import "tinymce/plugins/codesample"; //代码示例
import "tinymce/plugins/directionality"; //文字方向
import "tinymce/plugins/emoticons"; //表情
import "tinymce/plugins/fullpage"; //文档属性
// import "tinymce/plugins/fullscreen"; //全屏
import "tinymce/plugins/help"; //帮助
import "tinymce/plugins/hr"; //水平分割线
import "tinymce/plugins/importcss"; //引入css
import "tinymce/plugins/insertdatetime"; //插入日期时间
import "tinymce/plugins/link"; //超链接
import "tinymce/plugins/lists"; //列表插件
import "tinymce/plugins/media"; //插入编辑媒体
import 'tinymce/plugins/image'; // 插入图片
import "tinymce/plugins/nonbreaking"; //插入不间断空格
import "tinymce/plugins/pagebreak"; //插入分页符
import "tinymce/plugins/paste"; //粘贴插件
import "tinymce/plugins/preview"; //预览
import "tinymce/plugins/print"; //打印
import "tinymce/plugins/quickbars"; //快速工具栏
import "tinymce/plugins/save"; //保存
import "tinymce/plugins/searchreplace"; //查找替换
// import 'tinymce/plugins/spellchecker'  //拼写检查,未加入汉化,不建议使用
import "tinymce/plugins/tabfocus"; //切入切出,按tab键切出编辑器,切入页面其他输入框中
import "tinymce/plugins/table"; //表格
import "tinymce/plugins/template"; //内容模板
import "tinymce/plugins/textcolor"; //文字颜色
import "tinymce/plugins/textpattern"; //快速排版
import "tinymce/plugins/toc"; //目录生成器
import "tinymce/plugins/visualblocks"; //显示元素范围
import "tinymce/plugins/visualchars"; //显示不可见字符
import "tinymce/plugins/wordcount"; //字数统计
import { uploadImage, uploadVideo } from "@/api/fileApi"; export default {name: "TEditor",components: {Editor,},props: {value: {type: String,default: "",},disabled: {type: Boolean,default: false,},plugins: {type: [String, Array],default:"print preview searchreplace autolink directionality visualblocks visualchars fullscreen template code codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists image media wordcount textpattern autosave ",},toolbar: {type: [String, Array],default:"undo redo restoredraft | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | \styleselect formatselect fontselect fontsizeselect | bullist numlist | lists image table | blockquote subscript superscript removeformat | \table hr pagebreak insertdatetime print preview | code selectall searchreplace visualblocks | indent2em lineheight formatpainter axupimgs",},},data() {return {dialogVisible: false,video: {},init: {language_url: "tinymce/langs/zh_CN.js", //引入语言包文件language: "zh_CN", //语言类型skin_url: "tinymce/skins/ui/oxide", //皮肤:浅色// skin_url: '/tinymce/skins/ui/oxide-dark',//皮肤:暗色plugins: this.plugins, //插件配置toolbar: this.toolbar, //工具栏配置,设为false则隐藏// menubar: 'file edit',  //菜单栏配置,设为false则隐藏,不配置则默认显示全部菜单,也可自定义配置--查看 http://tinymce.ax-z.cn/configure/editor-appearance.php --搜索“自定义菜单”fontsize_formats:"12px 14px 16px 18px 20px 22px 24px 28px 32px 36px 48px 56px 72px", //字体大小font_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;", //字体样式lineheight_formats: "0.5 0.8 1 1.2 1.5 1.75 2 2.5 3 4 5", //行高配置,也可配置成"12px 14px 16px 20px"这种形式height: 275, //注:引入autoresize插件时,此属性失效placeholder: "在这里输入文字",branding: false, //tiny技术支持信息是否显示resize: "both", //编辑器宽高是否可变,false-否,true-高可变,'both'-宽高均可,注意引号// statusbar: false,  //最下方的元素路径和字数统计那一栏是否显示elementpath: false, //元素路径是否显示content_style: "img {max-width:100%;}", //直接自定义可编辑区域的css样式// content_css: '/tinycontent.css',  //以css文件方式自定义可编辑区域的css样式,css文件需自己创建并引入// images_upload_url: '/apib/api-upload/uploadimg',  //后端处理程序的url,建议直接自定义上传函数image_upload_handler,这个就可以不用了// images_upload_base_path: '/demo',  //相对基本路径--关于图片上传建议查看--http://tinymce.ax-z.cn/general/upload-images.phppaste_data_images: true, //图片是否可粘贴images_upload_handler: (blobInfo, success, failure) => {if (blobInfo.blob().size / 1024 / 1024 > 20) {failure("上传失败,图片大小请控制在 20M 以内");} else {let formData = new FormData();formData.append("picture", blobInfo.blob());formData.append("action", "add")uploadImage({ formData }).then((res) => {console.log(res)console.log('/media/' + res.pic)success('/media/' + res.pic);}).catch(() => {failure("上传出错,服务器开小差了呢");});}},},contentValue: this.value,};},watch: {value(newValue) {this.contentValue = newValue;},contentValue(newValue) {this.$emit("input", newValue);},},created() {},mounted() {tinymce.init({});},methods: {/**获取文件 */getFile(event) {this.video = event.target.files;this.$message.success("成功选择文件");},/** 提交添加视频请求*/addVideo() {var formData = new FormData();formData.append("file", this.video);console.log(formData.get("file"));uploadVideo(formData).then((res) => {if (this.contentValue === undefined) {tinymce.activeEditor.setContent(`<p><span class="mce-preview-object mce-object-video" contenteditable="false" data-mce-object="video" data-mce-p-allowfullscreen="allowfullscreen" data-mce-p-frameborder="no" data-mce-p-scrolling="no" data-mce-p-src=${res.location} "data-mce-html="%20"><video src=${res.location} width="100%" controls="controls"></video></span></p>`);} else {tinymce.activeEditor.setContent(this.contentValue +`<p><span class="mce-preview-object mce-object-video" contenteditable="false" data-mce-object="video" data-mce-p-allowfullscreen="allowfullscreen" data-mce-p-frameborder="no" data-mce-p-scrolling="no" data-mce-p-src=${res.location} "data-mce-html="%20"><video src=${res.location} width="100%" controls="controls"></video></span></p>`);}this.$message({type: "success",message: "添加成功",});}).catch(() => {this.$message({type: "error",message: "请先上传视频",});});},clickHandler() {this.dialogVisible = true;},handleClose() {this.dialogVisible = false;this.video = {};},// 添加相关的事件,可用的事件参照文档=> https://github.com/tinymce/tinymce-vue => All available eventsonClick(e) {this.$emit("onClick", e, tinymce);},//清空内容clear() {this.contentValue = "";},},
};
</script><style lang="less">
.tox-notifications-container {display: none;
}.tox-tinymce-aux {z-index: 5000 !important;
}
</style>

在要使用富文本框的地方引入tinymce组件

// 在需要使用富文本框的地方直接使用tinymce就可以了
<tinymcev-model="d":disabled="disabled"ref="editor"style="height: auto; border-radius: 22px"
></tinymce>import tinymce from "./tinymce";export default {components: { tinymce },name: "Home",data() {......}
}

vue 2.0项目中使用tinymce富文本框遇到的问题相关推荐

  1. 在vue3.0项目中使用tinymce富文本编辑器

    目录 一.安装 二.完整代码 三.事项说明 四.参考文档   之前看了好几篇关于 vue项目中使用 tinymce的文章, import引入大量 tinymce插件, /node_modules/ti ...

  2. Vue项目中使用 tinymce 富文本编辑器的方法,附完整源码

    来源 | https://blog.csdn.net/xingmeiok/article/deta 1.tinymce相关参考资料 tinymce版资料: http://tinymce.ax-z.cn ...

  3. vue管理后台项目中使用wangEditor富文本编辑器

    背景 公司需要做一个后台文章管理的模块,通过富文本编辑器编辑文章,在前端显示.调研了很久,决定使用wangEditor -- 轻量级 web 富文本编辑器,配置方便,使用简单.一些编辑器的说明. 开始 ...

  4. vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题

    1.如何设置config中的内容 readonly:true,//只读模式wordCount:false,//是否开启字数统计enableAutoSave: false,//自动保存功能 重点:ena ...

  5. tinymce富文本框踩坑

    tinymce富文本框踩坑 1.页面中需要多个富文本框时,每个富文本框的id必须做唯一标识,否则无法编辑 2.在tinymce富文本框需要做判断来显示时,谨慎使用v-if和v-show v-if会使富 ...

  6. Vue项目中使用wangEditor富文本输入框(推荐)

    vue中安装wangEditor cnpm install wangeditor 创建公用组件:在src/vue/components文件夹中创建wangEditor.vue <template ...

  7. 【Django 027】tinymce富文本框使用详解

    针对博客和论坛类网站,用户需要在网页的富文本框中输入内容传递到后端.那么Django项目如何生成一个包含富文本框的页码,又如何获取用户上传的富文本内容呢?这一节我们就一起来看看. 我是T型人小付,一位 ...

  8. 解决Vue用v-html、v-text渲染后台富文本框文本内容样式修改问题,用自定义css样式无法渲染出对应效果的问题

    举例: 如果您要加载富文本框内容的DOM id是detail 那么就这么写scss样式 #detail {font-size: 14px;text-align: center;&>> ...

  9. Vue 中使用 Tinymce 富文本编辑器

    参考链接:https://www.cnblogs.com/wisewrong/p/8985471.html Tinymce : 从 word 粘贴过来还能保持绝大部分格式的编辑器 一. 下载 npm ...

  10. 在Vue中使用Tinymce富文本编辑器+上传图片到七牛

    公司官网后台需要做一个上传新闻.公告的功能,自然而然就需要用到了富文本编辑器. UEditor.Simditor.wangEditor.CKEditor.TinyMCE.Quill,这是当前比较热门的 ...

最新文章

  1. Win10系列:UWP界面布局进阶1
  2. java基础之继承补充和抽象类
  3. 第四章 分支结构实验
  4. python序列类型-Python(第八课,序列类型)
  5. saltstack批量修改root密码
  6. System.Object 是 .NET 中所有类型的根吗?
  7. serialversionuid的作用_为什么阿里Java规约要求谨慎修改serialVersionUID字段
  8. 第4章 Python 数字图像处理(DIP) - 频率域滤波4 - 单变量的离散傅里叶变换DFT
  9. 案例:用一条 SQL 语句查询出每门课都大于 80 分的学生姓名
  10. CentOS增加用户到sudo用户组
  11. 读图,特征提取——形状
  12. 三个数比大小c语言_C语言必学知识点【结构体】用法很多,坑也很多!
  13. REACT打印页面组件
  14. 象棋在线对战网页源码源码安装
  15. 举例说明儿化音的作用_六年级语文下学期复习资料
  16. 非线性动力学常见的分析方法包括
  17. RSE2021/云检测:Automatic cloud and cloud shadow detection in tropical areas用于PlanetScope热带地区自动云和云阴影检测
  18. 算法与数据结构学习路线
  19. 关于微信公众号文章编辑器不能直接编辑html样式的处理方法
  20. 计嵌 廖峻 20178303040 C++作业

热门文章

  1. excel游戏_Excel集中游戏
  2. win10 MAC地址绑定及解绑
  3. 全世界所有程序员都会犯的错误-蔡学镛
  4. 在ArcCatalog10.2中改变元数据格式以及将元数据导出为HTML格式
  5. 获取KVM虚拟机IP地址
  6. 关系型数据和文档型数据库有什么区别?
  7. 打印图片一直显示连接传真服务器,打印机打印时显示传真怎么办
  8. PLC供电系统电源模块的选择
  9. 航迹推演(Odometry)
  10. python3爬虫(2):使用Selenium爬取百度文库word文章