封装好的代码 复制直接使用
<template>
<div class="tinymce-box">
<Editor v-model="myValue" :init="init" :disabled="disabled" class="sss" @click="onClick"> </Editor>
</div>
</template>
<script setup>
import tinymce from 'tinymce/tinymce';
import Editor from '@tinymce/tinymce-vue';
import 'tinymce/skins/content/default/content.css';
import 'tinymce/themes/silver/theme.min.js';
import 'tinymce/icons/default/icons';
import 'tinymce/plugins/image';
import 'tinymce/plugins/media';
import 'tinymce/plugins/table';
import 'tinymce/plugins/lists';
import 'tinymce/plugins/wordcount';
import 'tinymce/plugins/link';
import 'tinymce/plugins/code';
import 'tinymce/plugins/preview';
import 'tinymce/plugins/fullscreen';
import 'tinymce/plugins/help';
import { defineProps, ref, defineEmits, watch, toRef, computed } from 'vue';
const { plugins, toolbar, modelValue, minHeight } = defineProps({
modelValue: {
type: String,
default: '',
},
baseUrl: {
type: String,
default: window.location.origin ? window.location.origin : '',
},
disabled: {
type: Boolean,
default: false,
},
plugins: {
type: [String, Array],
default: 'link lists code table wordcount preview fullscreen',
},
toolbar: {
type: [String, Array],
default:
'bold italic underline strikethrough | fontsizeselect | formatselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent blockquote | undo redo | link unlink code lists table | removeformat | fullscreen preview',
},
minHeight: {
type: [String, Number],
default: 360,
},
});
const myValue = toRef(modelValue);
const init = ref({
language_url: '/public/tinymce/langs/zh_CN.js',
language: 'zh_CN',
model_url: `/public/tinymce/models/dom/model.js`,
skin_url: `/public/tinymce/skins/ui/oxide`,
content_css: '/public/tinymce/skins/content/document/content.css',
convert_urls: false,
min_height: minHeight,
max_height: 780,
plugins: plugins,
toolbar: toolbar,
statusbar: true,
menubar: 'file edit insert view format table tools help',
branding: false,
images_upload_handler: (blobInfo, success, failure) => {
const img = 'data:image/jpeg;base64,' + blobInfo.base64();
success(img);
console.log(failure, blobInfo);
},
});
const emit = defineEmits(['update:modelValue', 'handleClick']);
const onClick = (e) => {
emit('handleClick', e, tinymce);
};
watch(myValue, (val) => {
emit('update:modelValue', val);
});
</script>
<style scoped></style>
使用
<Tinymce v-model:modelValue="formInline.content" style="width: 100%"></Tinymce>