There are many rich text editors, the popular ones are UEditor, kindeditor, CKEditor and so on. But today we are going to implement the plugin development of tniyMCE. Install tinymce, tinymce ts, tinymce-vue declaration filesnpm install tinymce -S npm install @types/tinymce -S npm install @tinymce/tinymce-vue -S Package components<template> <div> <editor :id="id" v-model="content" :init="init"></editor> </div> </template> <script lang="ts"> import { Component, Prop, Vue, Watch } from 'vue-property-decorator'; import tinymce from 'tinymce'; import Editor from '@tinymce/tinymce-vue'; import 'tinymce/themes/silver/theme'; import 'tinymce/plugins/image'; import 'tinymce/plugins/link'; import 'tinymce/plugins/code'; 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/media'; import 'tinymce/plugins/fullscreen'; import 'tinymce/plugins/preview'; import 'tinymce/plugins/pagebreak'; import 'tinymce/plugins/insertdatetime'; import 'tinymce/plugins/hr'; import 'tinymce/plugins/paste'; import 'tinymce/plugins/codesample'; import 'tinymce/icons/default/icons'; console.log(tinymce); @Component({ name: 'TinymceEditer', components: { Editor } }) export default class extends Vue { //Set prop id @Prop({ default: 'vue-tinymce-' + +new Date() }) id!: string; //Default height @Prop({ default: 300 }) height!: number; @Prop({ default: '' }) private value!: string; private content: string = ''; @Watch('value') private onChangeValue(newVal: string) { this.content = newVal; } @Watch('content') private onChangeContent(newVal: string) { this.$emit('input', newVal); } //Rich text box init configuration private get init() { return { selector: '#' + this.id, //Rich text editor id language: 'zh_CN', //languagelanguage_url: '/tinymce/zh_CN.js', //language packageskin_url: '/tinymce/skins/ui/oxide', //The editor needs a skin to work properly, so set a skin_url to point to the skin file copied beforemenubar: false, //menu barplugins: 'link lists image code table colorpicker textcolor wordcount contextmenu media table fullscreen preview pagebreak insertdatetime hr paste codesample emoticons', //plugin toolbar: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : //Instantiate execution init_instance_callback: (editor: any) => { this.content && editor.setContent(this.content); //this.hasInit = true editor.on('NodeChange Change KeyUp SetContent', () => { //this.hasChange = true this.content = editor.getContent(); }); }, //Video settings callback video_template_callback: (data: any) => { return `<video width=" ${data.width} " height="${data.height}" ${data.poster ? 'poster="' + data.poster + '"' : ''} controls="controls"> <source src="${data.source}"/> </video>`; }, //Paste image callback images_upload_handler: (blobInfo: any, success: Function, failure: Function) => { this.handleImgUpload(blobInfo, success, failure); }, }; } private mounted() { this.content = this.value; } //Upload pictures private handleImgUpload(blobInfo: any, success: Function, failure: Function) { this.$emit('upload', blobInfo, success, failure); } } </script> <style lang="scss"> .tox-tinymce-aux { z-index: 3000 !important; } </style> Component Usage<template> <tinymce v-model="content" /> </template> <script lang="ts"> import { Component, Vue } from 'vue-property-decorator'; import Tinymce from '@/components/tinymce/tinymce.vue'; @Component({ components: Tinymce, }, }) export default class extends Vue { private content: string = ''; } </script> <style lang="scss" scoped></style> Vue uses Tinymce rich text editor to customize toolbar buttons
init: { language: "zh_CN", skin_url: "/tinymce/skins/ui/oxide", height: "100%", fontsize_formats: "8pt 10pt 12pt 14pt 16pt 18pt 24pt 36pt", font_formats: "Microsoft YaHei=Microsoft YaHei;Founder FangSong_GBK=Founder FangSong_GBK;Songti=simsun,serif;FangSongti=FangSong,serif;Boldti=SimHei;Times New Roman=Times New Roman;", plugins: { type: [String, Array], default: "code lists image media table wordcount indent2em" , toolbar: type: [String, Array], default: "code | lineheight | undo redo | fontsizeselect | fontselect | formatselect | bold italic forecolor backcolor | alignleft aligncenter alignright alignjustify | myCustomToolbarButton | bullist numlist outdent indent indent2em | lists image media table | removeformat" }, branding: false, menubar: false, setup: editor => { let _this = this; editor.ui.registry.addButton("myCustomToolbarButton", { text: "Shrink", onAction: function() { _this.show= !_this.show; } }); } }, Key Code
setup: editor => { let _this = this; editor.ui.registry.addButton("myCustomToolbarButton", { text: "Shrink", onAction: function() { _this.show= !_this.show; } }); } This is the end of this article about the practice of using Tinymce rich text to customize toolbar buttons in Vue. For more relevant Vue Tinymce custom toolbar content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Discussion on the Issues of Image Button Submission and Form Repeated Submission
>>: Solution to the problem that the vertical centering of flex inside button is not centered
A style sheet describes how a document should be ...
Table of contents Proxy forwarding rules The firs...
Preface The most common task after we install a L...
1. Introduction By enabling the slow query log, M...
When the DataSource property of a DataGrid control...
The SQL JOIN clause is used to join rows from two...
What is nGrinder? nGrinder is a platform for stre...
There is a difference between src and href, and t...
The principle of nginx to achieve resource compre...
This article example shares the specific code of ...
Log in docker login Complete the registration and...
Table of contents 1. Test experiment 2. Performan...
Implementation of regular backup of Mysql databas...
This article shares the specific code of Javascri...
This should be something that many people have do...