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. 2020-10-06:java中垃圾回收器让工作线程停顿下来是怎么做的?

    福大大答案2020-10-06: 简单回答:安全点,主动式中断. 中级回答:用户线程暂停,GC 线程要开始工作,但是要确保用户线程暂停的这行字节码指令是不会导致引用关系的变化.所以 JVM 会在字节码 ...

  2. 2022-06-21:golang选择题,以下golang代码输出什么?A:3;B:4;C:100;D:编译失败。 package main import ( “fmt“ ) func

    2022-06-21:golang选择题,以下golang代码输出什么?A:3:B:4:C:100:D:编译失败. package main import ( "fmt" ) fu ...

  3. uni-app介绍

    "优你"框架 uni-app 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS.Android.Web(响应式).以及各种小程序(微信/支付宝/ ...

  4. liunx操作系统下配置服务器

    centos7 下配置服务器基本步骤 1,yum install  服务器名称 2,关闭防火墙,配置服务器配置文件,开启服务, 3,创建文件,设置访问权限, 4,本地登陆,测试服务器能否连通

  5. 基于nerdctl+buildkitd+containerd实现镜像构建

    1.容器技术简介 容器技术除了的docker之外,还有coreOS的rkt.google的gvisor.以及docker开源的containerd.redhat的podman.阿⾥的pouch等,为了 ...

  6. pnpm才是前端工程化项目的未来

    前言 相信小伙伴们都接触过npm/yarn,这两种包管理工具想必是大家工作中用的最多的包管理工具,npm作为node官方的包管理工具,它是随着node的诞生一起出现在大家的视野中,而yarn的出现则是 ...

  7. 使用Mybatis-Plus问题解答

    我们使用一个新的框架难免会遇到各种问题,当然使用这款国产的优秀的Mybatis-Plus框架也不例外,下面我就给大家列举一下使用Mybatis-Plus可能遇到的一些问题,并做一下一一的解答. 1:如 ...

  8. STL-queue(ACM)

    重构函数(默认) queue<int> q; 基本操作 q.front(); // 队列最前面的元素q.back(); // 队列最后面的元素q.size(); // 返回队列长度q.em ...

  9. 第三届陕西省大学生网络安全技能部分WP

    web easyrce 题目代码如下: <?php error_reporting(0); highlight_file(__FILE__); if (!empty($_GET['PK'])){ ...

  10. 【HarmonyOS】API9中datashare转internal的方法

    [前言] HarmonyOS 3.1 Release版本正式发布了,这个版本给我们带来了一个非常有用的API--FilePicker(文件选择器) @ohos.file.picker,使用这个API我 ...