1、安装tinymce编辑器

npm i tinymce
npm i @tinymce/tinymce-vue

或:

yarn add tinymce

yarn add @tinymce/tinymce-vue

2、配置中文语言包

地址:中文语言包

注:最好将语言包放在public/langs/或static/langs/目录下,下面组件将会引用

3、封装组件

在components 目录下新建 tinymce.vue

<template>
<div>
<Editor :id="tinymceId" :init="init" :disabled="disabled" v-model="myValue"></Editor>
</div>
</template> <script>
//引入tinymce-vue
import Editor from '@tinymce/tinymce-vue'
//公共的图片前缀
//import Global from "./Global";
export default {
components: { Editor },
props: {
//编号
id: {
type: String
},
//内容
value: {
type: String,
default: ''
},
//是否禁用
disabled: {
type: Boolean,
default: false
},
//插件
plugins: {
type: [String, Array],
default: 'preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media code codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help emoticons autosave autoresize formatpainter',
},
//工具栏
toolbar: {
type: [String, Array],
default: 'code undo redo restoredraft | fullscreen | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | \
styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \
table image media charmap emoticons hr pagebreak insertdatetime print preview | bdmap indent2em lineheight formatpainter axupimgs',
}
},
data() {
let that = this;
return {
tinymceId: this.id || 'vue-tinymce' + Date.parse(new Date()),
myValue: this.value,
init: {
//汉化,路径是自定义的
language_url: '/tinymce/langs/zh_CN.js',
language: 'zh_CN',
//皮肤
skin: 'oxide',
//插件
plugins: this.plugins,
//工具栏
toolbar: this.toolbar,
//高度
height: 500,
//图片上传
images_upload_handler: function (blobInfo, success, failure) {
//文件上传的formData传递
let formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
//上传的api,和后端配合,返回的是图片的地址,然后加上公共的图片前缀
that.$api.system.uploadImage(formData).then(res => {
var url = "tt"//Global.baseUrlImg + res;
console.log(url)
success(url)
}).catch(res => {
failure('图片上传失败')
});
}
}
}
},
methods: { },
watch: {
//监听内容变化
value(newValue) {
this.myValue = newValue
},
myValue(newValue) {
this.$emit('input', newValue)
}
}
}
</script>
<style>
.tox-notifications-container {
display: none;
} /*在页面正常使用时不用加这个样式,在弹窗使用时,要加这个样式,因为使用弹窗,z-index层数比较低,工具栏的一些工具不能使用,要将z-index层数提高。*/
.tox.tox-silver-sink.tox-tinymce-aux {
z-index: 2100 !important;
}</style>

4、引用组件

新建test.vue

<template>
<div>
<TinymceEditor :value="content" @input="newContent"></TinymceEditor>
</div>
</template> <script>
import TinymceEditor from "./components/tinymce.vue"
export default {
components: {
TinymceEditor
},
data() {
return {
content: ""
}
},
methods: {
// 获取富文本的内容
newContent(val) {
this.content = val; // 直接更新 content 属性
}
}
}
</script>

注:文件引入路径是关键

vue中使用Tinymce的更多相关文章

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

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

  2. vue中TinyMCE图片 “data-mce-src” 属性的问题

    1.问题 在使用Vue中使用TinyMCE富文本编辑器时,上传的图片除了src属性还会多出来个"data-mcee-src" 属性,而保存时实际也是保存的"data-mc ...

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

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

  4. vue中如何不通过路由直接获取url中的参数

    前言:为什么要不通过路由直接获取url中的参数? vue中使用路由的方式设置url参数,但是这种方式必须要在路径中附带参数,而且这个参数是需要在vue的路由中提前设置好的. 相对来说,在某些情况下直接 ...

  5. vue中的重要特性

    一.vue中的自定义组件 html的代码: <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  6. Vue中comoputed中的数据绑定

    Vue中的数据实现响应式绑定是在初始化的时候利用definePrototype的定义set和get过滤器,在进行组件模板编译时实现water的监听搜集依赖项,当数据发生变化时在set中通过调用dep. ...

  7. vue中使用stompjs实现mqtt消息推送通知

    最近在研究vue+webAPI进行前后端分离,在一些如前端定时循环请求后台接口判断状态等应用场景用使用mqtt进行主动的消息推送能够很大程度的减小服务端接口的压力,提高系统的效率,而且可以利用mqtt ...

  8. Vue中应用CORS实现AJAX跨域,及它在 form data 和 request payload 的小坑处理

    基本概念部分(一):理解CORS 说道Vue的跨域AJAX,我想先梳理一遍CORS跨域,"跨域资源共享"(Cross-origin resource sharing),它是一个W3 ...

  9. vue中watched属性

    watched属性,vue中的观察属性,可用来监听一个值的变化 默认有两个参数,新值,旧值 data (){ return { currentCity: "深圳" } } watc ...

  10. 七、vue中v-for有时候对页面不会重新渲染,数组变化后如何到渲染页面

      v-for不能进行双向数据绑定,页面渲染完成后,再次更改v-for遍历的数据,js里面打印的数据看到数据值已经更改,但是页面的数据就是没有渲染,这是为什么呢? vue中v-for和angularj ...

随机推荐

  1. 2021-09-05:单词搜索 II。给定一个 m x n 二维字符网格 board 和一个单词(字符串)列表 words,找出所有同时在二维网格和字典中出现的单词。单词必须按照字母顺序,通过 相邻的

    2021-09-05:单词搜索 II.给定一个 m x n 二维字符网格 board 和一个单词(字符串)列表 words,找出所有同时在二维网格和字典中出现的单词.单词必须按照字母顺序,通过 相邻的 ...

  2. vue全家桶进阶之路7:Vue的第一个程序

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. ModuleNotFoundError: No module named 'flask_mail'

    ModuleNotFoundError: No module named 'flask_mail' 解决: pip install flask_mail

  4. OData WebAPI实践-与ABP vNext集成

    本文属于 OData 系列文章 ABP 是一个流行的 ASP. NET 开发框架,旧版的的 ABP 已经能够非常好的支持了 OData ,并提供了对应的 OData 包. ABP vNext 是一个重 ...

  5. Odoo-----计算字段、depnds,onchange 机制、模型约束

    1 计算字段和默认值问题 ​ 字段通过调用模型的方法的实时计算获得,一般都是 compute 属性为主的方法,这个计算方法通过计算self每条记录设置的的值,self 是一个有记录的有序集合,支持py ...

  6. day08-SpringCloud Gateway-服务网关

    SpringCloud Gateway-服务网关 1.Gateway介绍 1.1引出问题 没有使用网关服务时: 使用网关服务后: 1.2Gateway网络拓扑图 1.3Gateway是什么 官网:Sp ...

  7. Galaxy 生信平台(一):安装

    Galaxy Project( https://galaxyproject.org/)是在云计算背景下诞生的一个生物信息学可视化分析开源项目. 该项目由美国国家科学基金会(NSF).美国国家人类基因组 ...

  8. The shell

    The shell shell是什么? 如今的计算机有着多种多样的交互接口让我们可以进行指令的的输入,从炫酷的图像用户界面(GUI),语音输入甚至是 AR/VR 都已经无处不在. 这些交互接口可以覆盖 ...

  9. mybatis-plus-generator-ui 可视化代码生成器!

    它提供交互式的Web UI用于生成兼容mybatis-plus框架的相关功能代码,包括Entity,Mapper,Mapper.xml,Service,Controller等. 可以自定义模板以及各类 ...

  10. Elastaticsearch 集群部署

    系统Ubuntu 16.04 Elastaticsearch 5.6.9 Kibana 5.6.9 官网地址 https://www.elastic.co/products/elasticsearch ...