Преглед изворни кода

Add undefined check for instance methods (#3656)

* add undefined check for instance methods

* added a warning for undefined methods

* add production ENV check
Darius Tall пре 9 година
родитељ
комит
724a59348f
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      src/core/instance/state.js

+ 5 - 1
src/core/instance/state.js

@@ -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)
+      }
     }
   }
 }