`defaultValue` is invalid for `getFieldDecorator` will set `value`解决方案。
在使用vue的form表单校验的时候,使用的api是v-decorator。但是此处会报错。`defaultValue` is invalid for `getFieldDecorator` will set `value`, please use `option.initialValue` instead根据官网描述:this.form.getFieldDecorator(id, options
   ·  
 在使用vue的form表单校验的时候,使用的api是v-decorator。但是此处会报错。
`defaultValue` is invalid for `getFieldDecorator` will set `value`, please use `option.initialValue` instead
根据官网描述:
this.form.getFieldDecorator(id, options) 和 v-decorator="[id, options]"
  经过 getFieldDecorator或v-decorator 包装的控件,表单控件会自动添加 value(或 valuePropName 指定的其他属性) onChange(或 trigger 指定的其他属性),数据同步将被 Form 接管,这会导致以下结果:
你不再需要也不应该用 onChange 来做同步,但还是可以继续监听 onChange 等事件。
  你不能用控件的 value defaultValue 等属性来设置表单域的值,默认值可以用 getFieldDecorator 或 v-decorator 里的 initialValue。
  你不应该用 v-model,可以使用 this.form.setFieldsValue 来动态改变表单值。
所以在使用v-decorator时需要在其中设置initialValue
<a-select style="width:300px;" v-decorator="['id', {initialValue: '1'}]">
  <a-select-option v-for="item of userId" :key="item">
    {{ item }}
  </a-select-option>
</a-select>
更多推荐
 


所有评论(0)