diff --git a/src/core/observer/index.js b/src/core/observer/index.js index df734dbf09..cadabb7ee5 100644 --- a/src/core/observer/index.js +++ b/src/core/observer/index.js @@ -155,10 +155,7 @@ export function defineReactive ( childOb.dep.depend() } if (Array.isArray(value)) { - for (let e, i = 0, l = value.length; i < l; i++) { - e = value[i] - e && e.__ob__ && e.__ob__.dep.depend() - } + dependArray(value) } } return value @@ -234,3 +231,17 @@ export function del (obj: Object, key: string) { } ob.dep.notify() } + +/** + * Collect dependencies on array elements when the array is touched, since + * we cannot intercept array element access like property getters. + */ +function dependArray (value: Array) { + for (let e, i = 0, l = value.length; i < l; i++) { + e = value[i] + e && e.__ob__ && e.__ob__.dep.depend() + if (Array.isArray(e)) { + dependArray(e) + } + } +}