Skip to content

Commit 6fecabe

Browse files
committed
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 vuejs#8129. Codepen demonstrating the issue available at https://codepen.io/chrisvfritz/pen/rvzgBR?editors=1010 fix vuejs#8129
1 parent 5e3823a commit 6fecabe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/core/observer/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,15 @@ export function defineReactive (
196196
* already exist.
197197
*/
198198
export function set (target: Array<any> | Object, key: any, val: any): any {
199-
if (process.env.NODE_ENV !== 'production' &&
200-
(isUndef(target) || isPrimitive(target))
201-
) {
202-
warn(`Cannot set reactive property on undefined, null, or primitive value: ${(target: any)}`)
199+
if (process.env.NODE_ENV !== 'production') {
200+
if (isUndef(target) || isPrimitive(target)) {
201+
warn(`Cannot set reactive property on undefined, null, or primitive value: ${(target: any)}`)
202+
}
203+
if (Object.getOwnPropertyDescriptor(target, key) &&
204+
(typeof (Object.getOwnPropertyDescriptor(target, key).get) === 'undefined') &&
205+
!Array.isArray(target)) {
206+
warn(`Cannot enable reactivity on a property that is already defined: ${(key: any)}`)
207+
}
203208
}
204209
if (Array.isArray(target) && isValidArrayIndex(key)) {
205210
target.length = Math.max(target.length, key)

0 commit comments

Comments
 (0)