Skip to content

Commit

Permalink
fix: In development mode, warns if user tries to Vue.set a property t…
Browse files Browse the repository at this point in the history
…hat 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
  • Loading branch information
bigtunacan committed May 6, 2018
1 parent 5e3823a commit 6fecabe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/observer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,15 @@ export function defineReactive (
* already exist.
*/
export function set (target: Array<any> | 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)
Expand Down

0 comments on commit 6fecabe

Please sign in to comment.