1.安装tinymce插件命令
npm i tinymce @packy-tang/vue-tinymce
2.在main.js文件中全局引入tinymce相关文件(看项目需要,也可以在需要的组件中按需引入)
import tinymce from 'tinymce'
import VueTinymce from '@packy-tang/vue-tinymce'
Vue.prototype.$tinymce = tinymce
Vue.use(VueTinymce)
3.到node_modules目录下找到tinymce文件夹,复制到public目录下;
4.在public目录下新建langs文件夹,在里面新建zh-Hans.js文件处理中文。网址:[https://www.tiny.cloud/get-tiny/language-packages/]
5.找到public目录下index.html文件,在body中添加
<script src="/tinymce/tinymce.min.js"></script>
6.页面使用
<div class="tinymce-editor">
<vue-tinymce ref="editor"
class="editor overflow-scroll"
v-model="content"
:setting="setting" />
</div>
7.在data数据中对富文本进行配置
setting: {
branding: false,
inline: false,
menubar: true,
autosave_restore_when_empty: true,
save_enablewhendirty: true,
autoresize_on_init: true,
draggable_modal: true,
toolbar: "code undo redo | quickimage forecolor backcolor bold italic underline strikethrough anchor | alignleft aligncenter alignright alignjustify outdent indent | styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | table charmap emoticons hr pagebreak insertdatetime print preview | fullscreen | bdmap indent2em lineheight formatpainter axupimgs |",
plugins: "print quickbars preview searchreplace autolink directionality visualblocks visualchars fullscreen image imagetools link code codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount imagetools textpattern help emoticons autosave bdmap indent2em autoresize formatpainter axupimgs uploadimage",
language: "zh-Hans",
resize: true,
elementpath: false,
quickbars_insert_toolbar: false,
promotion: false,
min_height: 400,
max_height: 650,
quickbars_insert_toolbar: false,
quickbars_selection_toolbar: 'bold italic underline strikethrough forecolor backcolor',
},