vue-quill-editor设置必填和长度限制的提示

第一种方式是依赖 Formitem 插件。

Form 里增加:rules="ruleValidate" 

FormItem里增加 prop=”quillEditor”属性,然后再定义 ruleValidate 规则如下:

ruleValidate: {
    quillEditor: [
        {validator: validateQuillEditor, trigger: 'blur'}
    ]
},

其中的 validateQuillEditor 如下所示:

const validateQuillEditor = (rule, value, callback) => {
                if (this.flag) {
                    this.result = this.form.groupTemplates[this.date.groupIndex].formComponentTemplateDtoList[this.date.componentIndex][0];
                }
                if (this.result.strValue.length >= this.result.decimalNum) {
                    callback(new Error('只能输入'+ this.result.decimalNum +'个字'));
                } else {
                    callback();
                }
            };

第二种是使用quill-editor自带的方法进行限制,

@change="alertValue($event,strValue,decimalNum)"
alertValue(e,strValue,decimalNum){
    e.quill.deleteText(decimalNum,1,strValue);//保留 strValue 的 前 decimalNum 位字符,
}

猜你喜欢

转载自blog.csdn.net/bc_aptx4869/article/details/79851450
今日推荐