当前位置:网站首页>Error in v-on handler: "typeerror: cannot read property 'resetfields' of undefined"

Error in v-on handler: "typeerror: cannot read property 'resetfields' of undefined"

2022-04-23 16:57:00 Sister Gardenia

vue The project with elm Frame write form
When adding, the data should be cleared this.$refs['form'].resetFields();
But when the page loads in, it hasn't been rendered yet dom Elements
Therefore, clicking Add directly will report an error :

Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'resetFields')"

Solution :
1、 Add judgment

if(this.$refs['form'] !== undefined) {
    
  this.$refs['form'].resetFields();
}

2、 Delay callback

this.$nextTick(() => {
    
	this.$refs['form'].resetFields();
})

版权声明
本文为[Sister Gardenia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231653256248.html