vue + TinyMCE实现富文本编辑器

首先下载依赖

npm install tinymce --save
yarn add tinymce

然后我们可以封装一个方法,以便于我们调用,这里我还加入了图片的上传,假设这个文件是utils/article

import { uploadMessageImg } from "@/api/message";
export const editorInit = {
    language: "zh_CN",
    height: "600px",
    convert_urls: false,
    branding: false,
    plugins: [
        "advlist anchor autolink autosave code codesample colorpicker colorpicker contextmenu directionality emoticons fullscreen hr image imagetools importcss insertdatetime link lists media nonbreaking noneditable pagebreak paste preview print save searchreplace spellchecker tabfocus table template textcolor textpattern visualblocks visualchars wordcount axupimgs"
    ],
    toolbar: [
        "searchreplace bold italic underline strikethrough alignleft aligncenter alignright outdent indent  blockquote  removeformat subscript superscript code codesample",
        // "hr bullist numlist link image charmap pagebreak insertdatetime fullscreen axupimgs",
        'fontselect | fontsizeselect  | forecolor backcolor'
    ],
    images_upload_handler: function (blobInfo, success, failure) {
        const formData = new FormData();
        formData.append("file", blobInfo.blob());
        uploadMessageImg(formData)
            .then(res => {

                console.dir(res)
                const { code, data } = res
                if (code == 200) {
                    success('地址' + data.id);
                } else {
                    success()
                }

            })
            .catch(() => {
                failure("上传失败,请重新上传");
            });
    }
};

然后使用

<template>
    <editor v-model="form.docText" :init="editorInit" />
</template>

<script>
import Editor from '@tinymce/tinymce-vue';
import { editorInit } from '@/utils/article';
export default {
    components: {
        Editor,
    },
    data:{
        form:{},
        editorInit
    },
    methods:{
    }
}
</script>

大家可以参考一下中文文档:TinyMCE中文文档中文手册

相关推荐

  1. vue + TinyMCE实现文本编辑器

    2024-07-16 09:24:01       25 阅读
  2. React文本编辑器wangEditor

    2024-07-16 09:24:01       59 阅读
  3. 前端 文本编辑器原理

    2024-07-16 09:24:01       51 阅读
  4. uni-app 文本编辑器

    2024-07-16 09:24:01       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-16 09:24:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 09:24:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 09:24:01       58 阅读
  4. Python语言-面向对象

    2024-07-16 09:24:01       69 阅读

热门阅读

  1. 如何在本网站中显示所有Logistic回归超参数

    2024-07-16 09:24:01       25 阅读
  2. NIO(NO-Blocking I/O)模型

    2024-07-16 09:24:01       24 阅读
  3. 等保2.0 测评 linux服务器加固 基本安全配置手册

    2024-07-16 09:24:01       28 阅读
  4. PolarDB MySQL与RDS以及社区MySQL有什么区别?

    2024-07-16 09:24:01       21 阅读
  5. Memcached开发(二):安装与配置

    2024-07-16 09:24:01       21 阅读
  6. mysql第八天

    2024-07-16 09:24:01       23 阅读
  7. Apache httpd-vhosts.conf 配置详解(附Demo)

    2024-07-16 09:24:01       21 阅读
  8. 08-8.5.2 基数排序

    2024-07-16 09:24:01       19 阅读
  9. Redis如何做到重启数据不丢失?

    2024-07-16 09:24:01       22 阅读
  10. DP讨论——适配器模式

    2024-07-16 09:24:01       23 阅读