antd vue 表单 You cannot set a form field before rendering a field
antd使用form 表单,出现警告 You cannot set a form field before rendering a field associated with the valuebug样子warning.js?d96e:34 Warning: You cannot set a form field before rendering a field associated with t
·
antd使用form 表单,出现警告 You cannot set a form field before rendering a field associated with the value
bug样子
warning.js?d96e:34 Warning: You cannot set a form field before rendering a field associated with the value. You can use getFieldDecorator(id, options)
instead v-decorator="[id, options]"
to register it before render.
第一行得
解决
通常 在this.$nextTick()中使用this.form.setFieldsValue即可解决
但是,这里不一样,上代码
edit (id, type) {
this.list = []
this.visible = true
const { form: { setFieldsValue, resetFields } } = this
if (['edit', 'show', 'link', 'removeLink'].includes(type)) {
this.confirmLoading = true
getObj(id).then(res => {
const record = res.data
record.park = [] // 问题就出在这里
record.park.push(res.data.parkId)// 问题就出在这里
this.confirmLoading = false
this.$nextTick(() => {
setFieldsValue(pick(record, ['id', 'name', 'phone', 'imgUrl', 'remark', 'park', 'allId']))
})
}).catch(err => {
this.$message.error(err.msg)
this.confirmLoading = false
this.visible = false
})
} else {
resetFields()
}
},
原因:这里得park字段是没有用到得,所以移除了之后就没用问题了。
说白了,park字段还没有被注册
注意:使用 getFieldsValue getFieldValue setFieldsValue 等时,应确保对应的 field 已经用 getFieldDecorator 或 v-decorator 注册过了。
更多推荐
已为社区贡献13条内容
所有评论(0)