vue-quill-editor设置disabled

本文介绍如何使用vue-quill-editor实现富文本编辑器的禁用效果,通过添加disabled属性并利用enable方法控制编辑状态,适用于需要限制编辑功能的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近项目用到了vue-quill-editor,但是有场景要给富文本编辑器添加disabled效果,查看官网api后得到以下解决方案,直接上代码

html:

<template>
    <div 
        class="my-editor-comp">
        <quill-editor 
            :class="[disabled ? 'is-disabled' : '']"
            v-model="content" 
            ref="myQuillEditor" 
            :options="options" 
            @focus="onFocus($event)"
            @blur="onBlur($event)">
        </quill-editor>
    </div>
</template>

js:

<script>
// 添加富文本编辑器require配置
import { quillEditor } from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
export default {
    name: 'MyEditor',
    components: {
        quillEditor
    },
    data(){
        return{
            // 是否显示按钮
            disabled: false,
            // 富文本内容
            content: "",
            // 富文本配置
            options: {
                modules: {
                    toolbar: {
                        container: [
                            ['bold','italic','underline','strike'],
                            [{'size':['small', false, 'large', 'huge']}],
                            [{ 'color' : [] }, { 'background' : [] }],
                            [{ 'font' : [] }],
                            [{ 'align' : [] }],
                            ['link', 'image'],
                        ],
                    }               
                },
                placeholder: "请输入",
            },
        }
    },
    methods: {
        /** 
         * @method 鼠标进入
        */
        onMouseover(){
            if(this.disabled){
                this.$refs.myQuillEditor.quill.enable(false);
            }
        },
        /** 
         * @method 鼠标离开
        */
        onMouseleave(){
            if(this.disabled){
                this.$refs.myQuillEditor.quill.enable(true);
            }
        },
    }
}
</script>

 

实现核心:

富文本的enable方法,官网解释如下

 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值