vue 封装ueditor富文本编辑器(百度富文本编辑器)组件,支持双向绑定

开发环境:vue.js 2.0

文件名称:ueditor.vue 

<template>

    <div>

        <div :id="this.id"></div>

    </div>

</template>



<script>

    module.exports ={

        name: 'editor',

        props: ['id','value'],

        model: {

            prop: 'value',

            event: 'input',

        },

        data() {

            return {

                ue: '', //ueditor实例

                content: '', //编辑器内容

            }

        },

        methods: {

            //初始化编辑器

            initEditor() {

                this.ue = UE.getEditor(this.id, {

                    initialFrameWidth: '100%',

                    initialFrameHeight: '250',

                    scaleEnabled: false

                })

               

                //编辑器准备就绪后会触发该事件

                this.ue.addListener('ready',()=>{

                    //设置可以编辑

                    this.ue.setEnabled();

                    if(this.value != null)

                        this.ue.setContent(this.value);

                });

                //alert(this.data);

                //编辑器内容修改时

                //this.selectionchange();.  

                this.ue.addListener('blur', () => {

                    this.content = this.ue.getContent();

                    //this.data = this.content;

                    if(this.content == this.value){

                        return;

                    }

                    this.$emit('input',this.content);

                    this.$emit('change');

                })

               

            },

           

            //编辑器内容修改时

            //selectionchange() {

           

            //}

        },

        activated() {

            //初始化编辑器

            this.initEditor();

        },

        mounted() {

            //初始化编辑器

            this.initEditor();

        },

        destroyed() {

            //销毁编辑器实例,使用textarea代替

            this.ue.destroy();

            //重置编辑器,可用来做多个tab使用同一个编辑器实例

            //如果要使用同一个实例,请注释destroy()方法

            //this.ue.reset()

        }

    }

</script>




<style >

   

    .params .el-form-item__content{

        line-height: 0px !important;

        position: relative;

        font-size: 14px;

    }

</style>

使用示例:

1)引入vue.js 与httpVueLoade.js,示例:

<!--vue-->
<script src="/lib/vue/vue-2.6.11.min.js"></script>
<!-- vue组件解析 -->
<script src="/lib/httpVueLoader-1.4.2.js"></script>

文件下载地址:

链接:https://pan.baidu.com/s/1ydW88GgwJOu1jg6ifkZgAA 
提取码:zxew

2)new Vue()components 引入组件

new Vue({

        el:"#app",

        data:{

        },

        methods:{

        },    

        components: {

            // 引入富文本编辑器组件
            'ueditor':"url:/component/ueditor.vue"

    }

})

3) 在页面上调用组件

<ueditor id="'content" v-model="content"  @change="contentChange(index)">
</ueditor>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了禁止vue-ueditor-wrap富文本编辑器的编辑功能,你可以在使用组件的地方加上一个属性来禁用编辑。根据引用和引用中的代码,你可以在main.js和App.vue中添加以下代码: 在main.js中: ``` import VueUeditorWrap from 'vue-ueditor-wrap' Vue.component('vue-ueditor-wrap', { ...VueUeditorWrap, props: { disabled: { type: Boolean, default: false } }, mounted: function() { if (this.disabled) { this.$refs.ueditor.setDisabled() } } }) new Vue({ render: h => h(App), }).$mount('#app') ``` 在App.vue中: ``` <template> <div id="app"> <VueUeditorWrap :disabled="true"></VueUeditorWrap> </div> </template> <script> import VueUeditorWrap from 'vue-ueditor-wrap' export default { components: { VueUeditorWrap } } </script> ``` 这样设置之后,vue-ueditor-wrap富文本编辑器就会被禁用,用户将无法编辑其中的内容。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vue-ueditor-wrap百度富文本的使用](https://blog.csdn.net/qq_52883064/article/details/129875979)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [vue项目引入vue-ueditor-wrap富文本编辑器](https://blog.csdn.net/weixin_45966674/article/details/123498254)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值