Explorar o código

warn computed properties that are already defined as data or props

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
e7e86fd08b
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  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.
     if (!(key in vm)) {
       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)
+      }
     }
   }
 }