vue中对于多个input输入框如何验证以及如何返现

在使用ant-design时,有时需要随意的增加或者减少输入框,输入框的动态增加或者减少,该如何进行一个输入值的验证以及输入框的返现

在写input时可以这样写

<a-form-item
  v-if="item.type !== 'TRACKING_VIEWABILITY'"
  style="display: inline-flex; width: 219px; margin-left: 12px"
  :wrapperCol="{ lg: { span: 24 }, sm: { span: 24 } }"
>
  <a-input
    required
    :maxLength="1024"
    v-decorator="[
      `ThirdPartyMonitoringContent[${index}]`,
      {
        initialValue: '',
        rules: [
          { required: true, message: $t('creative.form.detectionNotEmpty') },
          { validator: validateUrl }
        ]
      }
    ]"
  >
  </a-input>
</a-form-item>

再进行一个返现时可以这样操作

 const formData = {
   ThirdPartyMonitoringContent: []
 }
 this.model.trackings.forEach((item, i) => {
   formData[`ThirdPartyMonitoringContent[${i}]`] = item.trackingUrl
   fields.push(`ThirdPartyMonitoringContent[${String(i)}]`)
 })
// 防止表单未注册
fields.forEach((v) => this.formCreative.getFieldDecorator(v))
this.formCreative.setFieldsValue(pick(formData, fields))

你可能感兴趣的:(vue.js,javascript,前端)