فهرست منبع

warn computed properties that clash with existing properties (close #4562)

Evan You 9 سال پیش
والد
کامیت
2b67eeca4d
1فایلهای تغییر یافته به همراه8 افزوده شده و 0 حذف شده
  1. 8 0
      src/core/instance/state.js

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

@@ -112,6 +112,14 @@ const computedSharedDefinition = {
 
 function initComputed (vm: Component, computed: Object) {
   for (const key in computed) {
+    /* istanbul ignore if */
+    if (process.env.NODE_ENV !== 'production' && key in vm) {
+      warn(
+        `existing instance property "${key}" will be ` +
+        `overwritten by a computed property with the same name.`,
+        vm
+      )
+    }
     const userDef = computed[key]
     if (typeof userDef === 'function') {
       computedSharedDefinition.get = makeComputedGetter(userDef, vm)