Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access of array per index isn't tracked #2427

Closed
javie5 opened this issue Oct 19, 2020 · 4 comments
Closed

Access of array per index isn't tracked #2427

javie5 opened this issue Oct 19, 2020 · 4 comments
Labels
🐞 bug Something isn't working scope: reactivity

Comments

@javie5
Copy link

javie5 commented Oct 19, 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

@javie5
Copy link
Author

javie5 commented Oct 19, 2020

I want to know why please

@posva posva changed the title Use 'for (index in array) {}' in computed or methods. When the array is initialized to empty, adding array items cannot refresh the view for of inside of a computed doesn't track changes Oct 19, 2020
@posva posva added scope: reactivity 🐞 bug Something isn't working labels Oct 19, 2020
@edison1105
Copy link
Member

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

@posva posva changed the title for of inside of a computed doesn't track changes Access of array per index isn't tracked Oct 19, 2020
@07akioni
Copy link
Contributor

07akioni commented Oct 19, 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

tc39/ecma262#367


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

@javie5
Copy link
Author

javie5 commented Oct 20, 2020

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

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

@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working scope: reactivity
Projects
None yet
Development

No branches or pull requests

4 participants