current position:Home>Vue -- rules dynamically determine the Boolean value of require and 1-255 regular expressions

Vue -- rules dynamically determine the Boolean value of require and 1-255 regular expressions

2022-01-27 04:35:40 Rolling mill

Scene: the repetition : Whether an input box must be input depends on the selection box above to control its display and hiding

 

  How to dynamically influence rules Of require Well ?

At first I wrote data in

rules:{
        deviceName: [
          { min: 0, max: 18, message: ' The length of equipment name shall not be longer than 18 position ', trigger: 'blur'}
        ],
        ip:[
          { required: true, message: ' Please enter ip Address ', trigger: 'blur' },
          { validator: validateIp,  trigger: 'blur' }
        ],
        gateway:[
          { required: true, message: ' Please enter gateway ', trigger: 'blur' },
          { validator: validateIp,  trigger: 'blur' }
        ],
        mask:[
          { required: true, message: ' Please enter the subnet mask ', trigger: 'blur' },
          { validator: validateIp,  trigger: 'blur' }
        ]
      },

  Shallow talent and sparse learning , Find out require You can't write variables directly

In order to finish the work as soon as possible, I choose to write in template in

 

        <el-form-item
          label=" Chassis number :"
          prop="caseID"
          v-show="form.delivery"
          :rules="[{required:form.delivery,message: ' Please enter the chassis number ',trigger:'blur'},            {pattern:/^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5]))))$/,message: ' The input is not in the correct format ',trigger:'blur'}]">
            <el-input v-model="form.caseID"></el-input>
        </el-form-item>

Implementation requirements

The chassis number needs 1-255 Between : The regular expression is /^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5]))))$/

copyright notice
author[Rolling mill],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270435372103.html

Random recommended