From 6fecabe3e2c2c43a177ea025d926f386db420a72 Mon Sep 17 00:00:00 2001 From: Joiey Seeley Date: Sat, 5 May 2018 19:26:41 -0500 Subject: [PATCH] fix: In development mode, warns if user tries to Vue.set a property that already exists. In development mode, warns if user tries to Vue.set a property that already exists. Issue reported in #8129. Codepen demonstrating the issue available at https://codepen.io/chrisvfritz/pen/rvzgBR?editors=1010 fix #8129 --- src/core/observer/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/observer/index.js b/src/core/observer/index.js index 35469aaf16..ab730dfe3f 100644 --- a/src/core/observer/index.js +++ b/src/core/observer/index.js @@ -196,10 +196,15 @@ export function defineReactive ( * already exist. */ export function set (target: Array | Object, key: any, val: any): any { - if (process.env.NODE_ENV !== 'production' && - (isUndef(target) || isPrimitive(target)) - ) { - warn(`Cannot set reactive property on undefined, null, or primitive value: ${(target: any)}`) + if (process.env.NODE_ENV !== 'production') { + if (isUndef(target) || isPrimitive(target)) { + warn(`Cannot set reactive property on undefined, null, or primitive value: ${(target: any)}`) + } + if (Object.getOwnPropertyDescriptor(target, key) && + (typeof (Object.getOwnPropertyDescriptor(target, key).get) === 'undefined') && + !Array.isArray(target)) { + warn(`Cannot enable reactivity on a property that is already defined: ${(key: any)}`) + } } if (Array.isArray(target) && isValidArrayIndex(key)) { target.length = Math.max(target.length, key)