Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

useForm的bug #23

@w2ichan

Description

@w2ichan

declare function useForm(modelRef: Props, rulesRef?: Props, options?: {
immediate?: boolean;
deep?: boolean;
validateOnRuleChange?: boolean;
debounce?: DebounceSettings;
}): {
.......
};

function useForm(modelRef, rulesRef, options) {
var initialModel = cloneDeep(modelRef);
var validateInfos = {};
Object.keys(rulesRef).forEach(function (key) {
validateInfos[key] = {
autoLink: false,
required: isRequired(rulesRef[key])
};
});
......
}

rulesRef为非必填参数,但是useForm方法中,却没有判断rulesRef是否为undefined,直接进行Object.keys操作....这样会报错~

目前有解决办法

useForm(modelRef, reactive({}));

rulesRef必须为reactive对象,直接使用空对象会有警告,这是由于
watch(rulesRef, function () {
if (options && options.validateOnRuleChange) {
validate();
}
}, {
deep: true
})

这一段代码导致,所以watch必须是一个reactive对象,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions