uView icon indicating copy to clipboard operation
uView copied to clipboard

在uniapp-运行h5的环境下,$ref在组件内失效,导致uform的setrules方法调用失败

Open jianmu297 opened this issue 3 years ago • 2 comments

非page页面,而是自定义组件,放在mounted下的this.$refs.uForm.setRules(this.rules); 会报错 ”Cannot read property 'setRules' of undefined“,有什么好的解决办法吗

jianmu297 avatar Mar 03 '21 09:03 jianmu297

可以尝试一下nextTick

yatoku avatar May 10 '21 07:05 yatoku

组件里用 watch:{ formType(newVal, oldVal){ if(newVal){ this.$nextTick(()=>{ this.resetForm(); this.$refs.uForm.setRules(this.form[newVal].rules); }); } } }

或者页面调用组件里使用 onReady() { let uFormRef = this.$refs.formRef.$refs.uForm; uFormRef.setRules(uFormRef.model.rules); },

LTAND avatar Dec 01 '21 09:12 LTAND