use icon indicating copy to clipboard operation
use copied to clipboard

useForm的bug

Open w2ichan opened this issue 5 years ago • 0 comments

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

w2ichan avatar Oct 28 '20 09:10 w2ichan