Explorar el Código

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 hace 9 años
padre
commit
724a59348f
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  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)
+      }
     }
   }
 }