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

Unnecessary re-render happened when using v-model #10529

Closed
tangerball opened this issue Mar 15, 2024 · 2 comments
Closed

Unnecessary re-render happened when using v-model #10529

tangerball opened this issue Mar 15, 2024 · 2 comments

Comments

@tangerball
Copy link

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNp9UtFKwzAU/ZVrXrrB1jLmi6MbqAzUBxUVfAnI6O66zDQJSVoHpf/uTercEFkfSnLO6e05J2nZtTFpUyObsdwVVhgPDn1tFlyJymjroQWLG+hgY3UFCUkTrrgqtHIeKlfCPPCD5A6l1PCurVxfJMOjxCO95jDwwksczhctVwCB0hJTqcsBZ+Pjw9koCkd/UBrYhZl51pske7TxWBm58kg7gHw7WbRttNR1eUa7iAplag/NuNJrlHPOiOcMsp5ci4YosSE8+BwkE7LOFmGdZ0SSKs9O/sJGzDsyvxFlunNaUWsxD2eFroyQaJ+MFxSOsxlEJnAraubrIWLe1pTtBy+2WHz+g+/cPmCcPVt0aBukVg6cX9kSfU8vXx9xT+tfkjLWktRnyBek4uvgsZfd1GpNtk900e19PHuhyje33HtU7hAqGA3KLuo5o/tweyb60e40vYzf0UFSix8N2jCTCpym0/SKdd8o6tHx

Steps to reproduce

Edit one of the Input component, then check console.

What is expected?

After modifying the contents of msg, why is the test function method of v-if triggered?

What is actually happening?

Currently, after modifying the contents of msg, the test function method has been triggered.

System Info

No response

Any additional comments?

No response

@edison1105
Copy link
Member

This is as expected.

  • It is necessary to execute test() to confirm whether the value of v-if has changed.
  • The execution of test() does not imply that the elements of v-if will be re-rendered. Only when the value of test() changes, will it be re-rendered.

@Doctor-wu
Copy link
Contributor

Doctor-wu commented Mar 15, 2024

When you modified the contents of msg (which is a ref), it will trigger it's subscriber (which includes the render function) to update, so the render will re-run to update view. Thus test() will be re-run to check if should render it's sub-tree.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants