-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
computed
triggers watcher of sync twice
#9149
Comments
This is the expected behavior since the |
Yes, this is expected behavior. Because sync will cause the code to be executed synchronously, it will be executed twice here.If you want the watch to be executed once, you only need to remove sync. |
But I think the issue is that the computed property named Sorry, the title is a bit misleading, it just describes a result that I think is problematic |
This is expected, because you set the watch method to be synchronous. By default (pre), the watch method will only be executed once before rendering when there are multiple response changes. After setting to synchronization (sync), every time the monitored value changes, the callback function of the watch function will be executed immediately. |
sync2 and sync1 are two independent computed properties, they will be executed twice |
@baiwusanyu-c Ummm... But this means that the final computed depends on more other computed, when the dependencies collected by other computed are updated, the final computed will be updated many times? |
compated
triggers watcher of sync twicecomputed
triggers watcher of sync twice
The computed getter function will not be executed multiple times. When you perform |
I tried creating a Every times we click the plus button to increase the count, https://stackblitz.com/edit/vitejs-vite-nydxzy?file=src%2FApp.vue |
Although I know it’s reasonable for him to trigger twice, I don’t think it’s reasonable 😂 |
Before calling the watch function
When
When |
Fixed by #5912 |
Vue version
3.3.4
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-9dgxah?file=src%2FApp.vue
Steps to reproduce
update
become2
from0
. (expected is1
)What is expected?
According the following code, when
count
update once, the watcher should just run once.What is actually happening?
The watcher ran twice!
System Info
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: