Cannot read property ‘resetfields’ of undefined problem
Problem Description:
use element to develop background system, edit and add the same pop-up box
bind the commentform object in data
in order to clear the form in the new pop-up box, use this. $refs [formname]. Resetfields()
click Add to display the pop-up box for the first time, Will report an error
“[Vue warn]: error in event handler for” click “:” typeerror: cannot read property ‘resetfields’ of undefined “”
Cause of the problem: after mounted loads the table data, the hidden pop-up box is not compiled and rendered into the dom.
So @ Click = “dialogformvisible = true; Reset form (‘dlgform ‘) “when the click pops up
r
e
f
s
and
no
yes
Get
take
reach
d
o
m
element
element
guide
To
′
r
e
s
e
t
F
i
e
l
d
s
′
o
f
u
n
d
e
f
i
n
e
d
solution
Decision
square
method
:
one
、
(
Refs does not get DOM element, resulting in ‘resetfields’ of undefined solution: 1(
Refs does not get DOM element, resulting in ‘resetfields’ of undefined solution: 1. (after next update of nexttick DOM)
resetForm(formName) {
this.$nextTick(()=>{
this.$refs[formName].resetFields();
})
},
2. (if you click add for the first time, there is no need to reset. It is judged according to the element undefined.)
if (this.$refs[formName] !== undefined) {
this.$refs[formName].resetFields();
}
Note: a series of JS operations on DOM should be put into the callback function of Vue. Nexttick()
Read More:
- In Vue, use echorts to report an error: “typeerror: cannot read property ‘init’ of undefined” error reporting reason and solution
- [_ Note] Vue.js reported an error: Cannot read property’validate’ of undefined”
- Vue: cannot read property ‘substring’ of undefined“
- The Vue parent component uses ref to call the sub component method and reports an error
- Vue error resolution: TypeError: Cannot read property’_t’ of undefined”
- Vue error resolution: typeerror: cannot read property ‘_ t’ of undefined”
- Vue error in render: “typeerror: cannot read property ‘name’ of undefined”
- [Solved] Vue Error: TypeError: Cannot read property ‘end‘ of undefined
- Cannot read property ‘substring’ of undefined in Vue
- TypeError: Cannot read property ‘username‘ of undefined
- Cannot read property ‘properties’ of undefined
- Error reported by wechat applet: cannot read property ‘forceupdate’ of undefined
- Datatable plug-in error: uncaught typeerror: cannot read property ‘style’ of undefined
- Uncaught type error: cannot read property ‘MSIE’ of undefined
- TypeError: Cannot read property thisCompilation of undefined
- JS prompt cannot read property ‘style’ of undefined
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- Cannot read property ‘this compilation’ of undefined appears in copy webpack plugin
- Error in created hook: “typeerror: cannot read property ‘cm’ of undefined”
- Error in mounted hook: “TypeError: Cannot read property ‘init‘ of undefined“