vue中使用Tinymce的示例代码

 更新时间:2023年08月17日 09:00:34   作者:一个叶小小  
这篇文章主要介绍了vue中使用Tinymce的示例,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

1、安装tinymce编辑器

npm i tinymce
npm i @tinymce/tinymce-vue

或:

yarn add tinymce
yarn add @tinymce/tinymce-vue

2、配置中文语言包

地址:中文语言包

注:最好将语言包放在public/langs/或static/langs/目录下,下面组件将会引用

3、封装组件

在components 目录下新建 tinymce.vue

<template>
    <div>
        <Editor :id="tinymceId" :init="init" :disabled="disabled" v-model="myValue"></Editor>
    </div>
</template>
<script>
//引入tinymce-vue
import Editor from '@tinymce/tinymce-vue'
//公共的图片前缀
//import Global from "./Global";
export default {
    components: { Editor },
    props: {
        //编号
        id: {
            type: String
        },
        //内容
        value: {
            type: String,
            default: ''
        },
        //是否禁用
        disabled: {
            type: Boolean,
            default: false
        },
        //插件
        plugins: {
            type: [String, Array],
            default: 'preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media code codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help emoticons autosave autoresize formatpainter',
        },
        //工具栏
        toolbar: {
            type: [String, Array],
            default: 'code undo redo restoredraft | fullscreen | cut copy paste pastetext | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | \
    styleselect formatselect fontselect fontsizeselect | bullist numlist | blockquote subscript superscript removeformat | \
    table image media charmap emoticons hr pagebreak insertdatetime print preview | bdmap indent2em lineheight formatpainter axupimgs',
        }
    },
    data() {
        let that = this;
        return {
            tinymceId: this.id || 'vue-tinymce' + Date.parse(new Date()),
            myValue: this.value,
            init: {
                //汉化,路径是自定义的
                language_url: '/tinymce/langs/zh_CN.js',
                language: 'zh_CN',
                //皮肤
                skin: 'oxide',
                //插件
                plugins: this.plugins,
                //工具栏
                toolbar: this.toolbar,
                //高度
                height: 500,
                //图片上传
                images_upload_handler: function (blobInfo, success, failure) {
                    //文件上传的formData传递
                    let formData = new FormData();
                    formData.append('file', blobInfo.blob(), blobInfo.filename());
                    //上传的api,和后端配合,返回的是图片的地址,然后加上公共的图片前缀
                    that.$api.system.uploadImage(formData).then(res => {
                        var url = "tt"//Global.baseUrlImg + res;
                        console.log(url)
                        success(url)
                    }).catch(res => {
                        failure('图片上传失败')
                    });
                }
            }
        }
    },
    methods: {
    },
    watch: {
        //监听内容变化
        value(newValue) {
            this.myValue = newValue
        },
        myValue(newValue) {
            this.$emit('input', newValue)
        }
    }
}
</script>
<style>
.tox-notifications-container {
    display: none;
}
/*在页面正常使用时不用加这个样式,在弹窗使用时,要加这个样式,因为使用弹窗,z-index层数比较低,工具栏的一些工具不能使用,要将z-index层数提高。*/
.tox.tox-silver-sink.tox-tinymce-aux {
    z-index: 2100 !important;
}</style>

4、引用组件

新建test.vue

<template>
    <div>
        <TinymceEditor :value="content" @input="newContent"></TinymceEditor>
    </div>
</template>
<script>
import TinymceEditor from "./components/tinymce.vue"
export default {
    components: {
        TinymceEditor
    },
    data() {
        return {
            content: ""
        }
    },
    methods: {
        // 获取富文本的内容
        newContent(val) {
            this.content = val; // 直接更新 content 属性
        }
    }
}
</script>

注:文件引入路径是关键

到此这篇关于vue中使用Tinymce的文章就介绍到这了,更多相关vue使用Tinymce内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Vue3封装ant-design-vue表格的详细代码

    Vue3封装ant-design-vue表格的详细代码

    这篇文章主要介绍了Vue3封装ant-design-vue表格,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-05-05
  • Element-UI 使用el-row 分栏布局的教程

    Element-UI 使用el-row 分栏布局的教程

    这篇文章主要介绍了Element-UI 使用el-row 分栏布局的教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-10-10
  • vue轻量级框架无法获取到vue对象解决方法

    vue轻量级框架无法获取到vue对象解决方法

    这篇文章主要介绍了vue轻量级框架无法获取到vue对象解决方法相关知识点,有需要的读者们跟着学习下。
    2019-05-05
  • Vue+java实现时间段的搜索示例

    Vue+java实现时间段的搜索示例

    本文主要介绍了Vue+java实现时间段的搜索示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-06-06
  • vue项目使用luckyexcel预览excel表格功能(心路历程)

    vue项目使用luckyexcel预览excel表格功能(心路历程)

    这篇文章主要介绍了vue项目使用luckyexcel预览excel表格,我总共尝试了2种方法预览excel,均可实现,还发现一种方法可以实现,需要后端配合,叫做KKfileview,本文给大家介绍的非常详细,需要的朋友可以参考下
    2023-10-10
  • vue cli2 和 cli3去掉eslint检查器报错的解决

    vue cli2 和 cli3去掉eslint检查器报错的解决

    这篇文章主要介绍了vue cli2 和 cli3去掉eslint检查器报错的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-04-04
  • vue中ts无法识别引入的vue文件,提示找不到xxx.vue模块的解决

    vue中ts无法识别引入的vue文件,提示找不到xxx.vue模块的解决

    这篇文章主要介绍了vue中ts无法识别引入的vue文件,提示找不到xxx.vue模块的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-09-09
  • element-ui 表格数据时间格式化的方法

    element-ui 表格数据时间格式化的方法

    这篇文章主要介绍了element-ui 表格数据时间格式化的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-08-08
  • 通过vue手动封装on、emit、off的代码详解

    通过vue手动封装on、emit、off的代码详解

    这篇文章主要介绍了通过vue手动封装on,emit,off的代码详解,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-05-05
  • Vue之生命周期函数详解

    Vue之生命周期函数详解

    这篇文章主要为大家介绍了Vue之生命周期函数,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
    2021-11-11

最新评论