-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add undefined check for instance methods #3656
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,11 @@ function initMethods (vm: Component) { | |
const methods = vm.$options.methods | ||
if (methods) { | ||
for (const key in methods) { | ||
vm[key] = bind(methods[key], vm) | ||
if (methods[key] != null) { | ||
vm[key] = bind(methods[key], vm) | ||
} else if (process.env.NODE_ENV !== 'production') { | ||
warn(`The method ${key} on vue instance is undefined.`, vm) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious why do you provide vm as a second variable? it will log vm? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's used to get the component name, if available: https://github.com/vuejs/vue/blob/dev/src/core/util/debug.js#L10-L13 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh I get it, You saved me!!!!!!!!!! |
||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add
else if (process.env.NODE_ENV !== 'production')
here so that the warning can be stripped?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!