zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    技术领导要不要写代码?
    资深程序员告诉你:如何用五年时间攒够100万?
    mfc基于对话框的应用程序,如何设置初始对话框大小,移动控件位置
    zend studio,操作记录
    xampp怎么操作数据库mysql
    mysql-font的理解
    delphi 中配置文件的使用(*.ini)和TIniFile 用法
    delphi 创建服务,安装与卸载服务
    sublime Text的一些用法(emmet插件、)
    apache (web服务器) ->php->mysql,xampp与wamp比较,WAMP与WNMP有什么区别
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/15560479.html
Copyright © 2011-2022 走看看