• vue template 表单验证 vif bug All In One


    vue template 表单验证 v-if bug All In One

    template & v-if 表单验证会抽风,随机触发验证规则 bug

        <template v-if="isShowDeepBid && ruleForm.deepBidType === 'DEEP_BID_MIN'">
            <el-form-item class="is-required" label="出价" prop="deepConvertPrice"
                :rules="[
                    {
                        required: true,
                        message: '请输入出价,
                        trigger: 'blur',
                        validator: deepConvertPriceValidate,
                    },
                ]">
                <el-input
                    class="tm-convert-price"
                    style=" 300px;"
                    placeholder="请输入出价"
                    v-model="ruleForm.deepConvertPrice">
                    <span slot="suffix" class="tm-custom-suffix">元</span>
                </el-input>
            </el-form-item>
        </template>
    
    

    solution

    template v-if 下面的 el-form-item 添加 unique key

        <template v-if="isShowDeepBid && ruleForm.deepBidType === 'DEEP_BID_MIN'">
            <el-form-item class="is-required" label="出价" prop="deepConvertPrice" key="deepConvertPrice"
                :rules="[
                    {
                        required: true,
                        message: '请输入出价,
                        trigger: 'blur',
                        validator: deepConvertPriceValidate,
                    },
                ]">
                <el-input
                    class="tm-convert-price"
                    style=" 300px;"
                    placeholder="请输入出价"
                    v-model="ruleForm.deepConvertPrice">
                    <span slot="suffix" class="tm-custom-suffix">元</span>
                </el-input>
            </el-form-item>
        </template>
    
    
    
        <template v-if="isShowDeepBid && ruleForm.deepBidType === 'DEEP_BID_MIN'" key="deepConvertPrice">
            <el-form-item class="is-required" label="出价" prop="deepConvertPrice"
                :rules="[
                    {
                        required: true,
                        message: '请输入出价,
                        trigger: 'blur',
                        validator: deepConvertPriceValidate,
                    },
                ]">
                <el-input
                    class="tm-convert-price"
                    style=" 300px;"
                    placeholder="请输入出价"
                    v-model="ruleForm.deepConvertPrice">
                    <span slot="suffix" class="tm-custom-suffix">元</span>
                </el-input>
            </el-form-item>
        </template>
    
    

    手动触发校验

        deepBidTypeChange (value = '') {
            const vaildteDict = ['DEEP_BID_MIN', 'ROI_COEFFICIENT'];
            if(vaildteDict.includes(value)) {
                this.$emit('clear-validate-field-by-key', 'deepConvertPrice');
                this.$emit('clear-validate-field-by-key', 'roiGoal');
                this.$nextTick(() => {
                    const keyMap = new Map([['DEEP_BID_MIN', 'deepConvertPrice'], ['ROI_COEFFICIENT', 'roiGoal']]);
                    this.$emit('validate-field-by-key', keyMap.get(value));
                });
            }
        },
    
    

    refs



    ©xgqfrms 2012-2020

    www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

    原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!


    xgqfrms
  • 相关阅读:
    闲谈《一》
    GoldenGate系列一:快速搭建单向同步GoldenGate环境
    读取并分析wgetrc文件
    oracle之Flash Recovery Area全面介绍
    使用Subversion进行版本控制 附录A
    使用lstat()判断文件类型
    连接数据库时提示归档器失败 ORA00257: archiver error
    GoldenGate系统三:trouble shooting and log
    关于VMware虚拟机的上网
    使用C语言读取properties文件V1.0
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/15560479.html
Copyright © 2020-2023  润新知