From d5006ae453da11030c84ad253fd1a86a2d024294 Mon Sep 17 00:00:00 2001 From: MaoNianYou Date: Sat, 23 Oct 2021 23:26:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(u-form-item):=20=E5=BD=93form=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=B5=8C=E5=A5=97=E5=AF=B9=E8=B1=A1=E6=97=B6=E6=9C=AA?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E8=A1=A8=E5=8D=95=E9=A1=B9=E5=80=BC=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitee.com/xuqu/uView/issues/I2AYUY --- uview-ui/components/u-form-item/u-form-item.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/uview-ui/components/u-form-item/u-form-item.vue b/uview-ui/components/u-form-item/u-form-item.vue index d6b8c8b0..886ad63a 100644 --- a/uview-ui/components/u-form-item/u-form-item.vue +++ b/uview-ui/components/u-form-item/u-form-item.vue @@ -273,7 +273,7 @@ // 校验数据 validation(trigger, callback = () => {}) { // 检验之间,先获取需要校验的值 - this.fieldValue = this.parent.model[this.prop]; + this.fieldValue = this.getFieldValue(); // blur和change是否有当前方式的校验规则 let rules = this.getFilteredRule(trigger); // 判断是否有验证规则,如果没有规则,也调用回调方法,否则父组件u-form会因为 @@ -300,6 +300,19 @@ }); }, + /** + * 检验之前,先获取需要校验的值 + * 解决:当form属性嵌套对象时未取到值的问题 + * fix: [#I2AYUY](https://gitee.com/xuqu/uView/issues/I2AYUY) + */ + getFieldValue() { + const fields = this.prop.split('.'); + const value = fields.reduce((pre, cur) => { + return pre && pre[cur]; + }, this.parent.model); + return value; + }, + // 清空当前的u-form-item resetField() { this.parent.model[this.prop] = this.initialValue;