1.下载依赖
<!-- 默认是vue3 -->
npm install tinymce -S
npm install @tinymce/tinymce-vue -S
<!-- Vue2使用需要指定版本 -->
npm install tinymce@5.1.0 -S
npm install @tinymce/tinymce-vue@3.0.1 -S
2.下载压缩包解压放到public文件夹下
3.封装组件
<template>
<div class="tinymce-editor">
<editor
v-if="!reloading"
v-model="myValue"
:init="init"
:disabled="disabled"
@onClick="onClick"
>
</editor>
</div>
</template>
<script>
import tinymce from "tinymce/tinymce";
import Editor from "@tinymce/tinymce-vue";
import "tinymce/themes/silver/theme";
import "tinymce/plugins/image";
import "tinymce/plugins/link";
import "tinymce/plugins/media";
import "tinymce/plugins/table";
import "tinymce/plugins/lists";
import "tinymce/plugins/contextmenu";
import "tinymce/plugins/wordcount";
import "tinymce/plugins/colorpicker";
import "tinymce/plugins/textcolor";
import "tinymce/plugins/fullscreen";
import "tinymce/icons/default";
import { uploadAction } from "@/utils/ruoyi";
export default {
components: {
Editor,
},
props: {
value: {
type: String,
required: false,
},
triggerChange: {
type: Boolean,
default: false,
required: false,
},
disabled: {
type: Boolean,
default: false,
},
plugins: {
type: [String, Array],
default:
"lists image link media table textcolor wordcount contextmenu fullscreen",
},
toolbar: {
type: [String, Array],
default:
"undo redo | formatselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | lists link unlink image media table | removeformat | fullscreen",
branding: false,
},
},
data() {
return {
init: {
language_url: "/tinymce/langs/zh_CN.js",
language: "zh_CN",
skin_url: "/tinymce/skins/lightgray",
height: 300,
plugins: this.plugins,
toolbar: this.toolbar,
branding: false,
menubar: false,
toolbar_drawer: false,
images_upload_handler: (blobInfo, success) => {
let formData = new FormData();
formData.append("file", blobInfo.blob());
uploadAction("/common/upload", formData).then((res) => {
success(res.url);
});
},
},
myValue: this.value,
reloading: false,
};
},
mounted() {
},
methods: {
reload() {
this.reloading = true;
this.$nextTick(() => (this.reloading = false));
},
onClick(e) {
this.$emit("onClick", e, tinymce);
},
clear() {
this.myValue = "";
},
},
watch: {
value(newValue) {
this.myValue = newValue == null ? "" : newValue;
},
myValue(newValue) {
if (this.triggerChange) {
this.$emit("change", newValue);
} else {
this.$emit("input", newValue);
}
},
},
};
</script>
<style scoped></style>
4.使用
<JEditor v-model="taskContent"></JEditor>
import JEditor from "@/components/jeecg/JEditor.vue";
components: {
JEditor,
},
data() {
return {
taskContent:""
}