Browse Source

warn computed properties that are already defined as data or props

Evan You 9 years ago
parent
commit
e7e86fd08b
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/core/instance/state.js

+ 6 - 0
src/core/instance/state.js

@@ -165,6 +165,12 @@ function initComputed (vm: Component, computed: Object) {
     // at instantiation here.
     // at instantiation here.
     if (!(key in vm)) {
     if (!(key in vm)) {
       defineComputed(vm, key, userDef)
       defineComputed(vm, key, userDef)
+    } else if (process.env.NODE_ENV !== 'production') {
+      if (key in vm.$data) {
+        warn(`The computed property "${key}" is already defined in data.`, vm)
+      } else if (vm.$options.props && key in vm.$options.props) {
+        warn(`The computed property "${key}" is already defined as a prop.`, vm)
+      }
     }
     }
   }
   }
 }
 }