Skip to content

Commit 724a593

Browse files
Darius Tallyyx990803
Darius Tall
authored andcommitted
Add undefined check for instance methods (#3656)
* add undefined check for instance methods * added a warning for undefined methods * add production ENV check
1 parent 6f8316f commit 724a593

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/core/instance/state.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ function initMethods (vm: Component) {
142142
const methods = vm.$options.methods
143143
if (methods) {
144144
for (const key in methods) {
145-
vm[key] = bind(methods[key], vm)
145+
if (methods[key] != null) {
146+
vm[key] = bind(methods[key], vm)
147+
} else if (process.env.NODE_ENV !== 'production') {
148+
warn(`The method ${key} on vue instance is undefined.`, vm)
149+
}
146150
}
147151
}
148152
}

0 commit comments

Comments
 (0)