Subscribe on changes!

Access of array per index isn't tracked

avatar
Oct 19th 2020

Version

3.0.1

Reproduction link

https://codepen.io/javie5/pen/jOrrYVx

Steps to reproduce

Click the 'add item' button

What is expected?

array item grouping rendering

What is actually happening?

Use 'for (index in array) {}' in computed or methods. When the array is initialized to empty, adding array items cannot refresh the view

avatar
Oct 19th 2020

I want to know why please

avatar
Oct 19th 2020

@posva It's relate to for in , not for of.

avatar
Oct 19th 2020

Currently in JS there is no trap for for in in Proxy. So it may not be consider as a bug but rather a constraint of JS.

https://stackoverflow.com/questions/38586471/how-to-control-property-enumeration-for-in-with-proxy-objects

https://github.com/tc39/ecma262/pull/367


Although the behavior of for in can't be proxyed, ownKeys would be called when execute for in.

avatar
Oct 20th 2020

@yyx990803 可以请教下为什么以下2种情况使用for in 视图依然可以同步更新吗: 1.在computed 中使用for in时,同时使用array.length image

2.不使用数组,改用对象(初始化为空白对象) image