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

Fix dom not change while data change #18

Open
miyagipipi opened this issue Jul 31, 2024 · 3 comments
Open

Fix dom not change while data change #18

miyagipipi opened this issue Jul 31, 2024 · 3 comments

Comments

@miyagipipi
Copy link

When my data object changes (such as the state of an item affecting a button color), I find that dom actually hasn't changed.
I analyzed the source code and found that the code shown below caused the dom rendering delay issue due to setTimeout.

index.vue line 313
watch( () => props.data, (newVal, oldVal) => { ... setTimeout(scrollRender, 0); } );

I changed this to directly run scrollRender() instead of run setTimeout, and DOM promptly rendered the latest item state.

Why use setTimeout here?
The code in the scrollRender function not needs to wait a period of time before running.

Because in other watch, scrollRender is directly called, and if it is necessary to perform certain tasks after updating the DOM, vue nextTick can also be used to replace setTimeout.
If possible, I have a suggestion:

  1. Modify scrollRender so that the renderEnd function for DOM operations is not placed in the scrollRender function.
  2. In watch part, directly run scrollRender() , and then call await nextTick(renderEnd)
@drawcall
Copy link
Member

drawcall commented Jul 31, 2024

Thank you very much, I have limited energy and can submit a PR.

@ryrhjf
Copy link

ryrhjf commented Aug 12, 2024

你好,想请问一下可以详细的说一下解决方案吗?在项目里不知如何解决。

@miyagipipi
Copy link
Author

你好,想请问一下可以详细的说一下解决方案吗?在项目里不知如何解决。
源码的 index.vue 313 行
setTimeout(scrollRender, 0) 改为直接运行 scrollRender() 就能解决。
如果你的实际业务涉及到 renderEnd 函数相关的事件,就将它从 scrollRender 函数中抽出来,执行 await nextTick(renderEnd)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants