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

useForm的bug #23

Open
w2ichan opened this issue Oct 28, 2020 · 0 comments
Open

useForm的bug #23

w2ichan opened this issue Oct 28, 2020 · 0 comments

Comments

@w2ichan
Copy link

w2ichan commented Oct 28, 2020

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对象,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant