You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I commented out the stop effect loop, and the watcher was triggered with the correct new value. I also tried invoking the beforeUnmount hook after the stop effect loop, which stopped the watcher being triggered.
I think not trigger is the correct way. This is also the way of vue2.
This is an example, in response to the url parameter call api to get the page data, the code in the case of not trigger is:
// not triggersetup(){constdata=ref();watch(()=>$route.query.dataId,async()=>data.value=awaitfetchData($route.query.dataId),{immediate: true},)return{ data };}
If the trigger last value will require extra code to avoid triggering a useless api calling when leaving the page:
// trigger last valuesetup(){constdata=ref();letisOnBeforeUnmount=false;watch(()=>$route.query.dataId,async()=>{if(isOnBeforeUnmount)return;// getCurrentInstance().isUnmounted is false at last triggerdata.value=awaitfetchData($route.query.dataId);},{immediate: true},)onBeforeUnmount(()=>{isOnBeforeUnmount=true;});return{ data };}
Version
3.0.0-beta.18
Reproduction link
https://jsfiddle.net/82xpeomh/
Steps to reproduce
What is expected?
When toggling the component the watcher should either provide the newest value or not trigger
What is actually happening?
it is providing
undefined
This happens when the computed needs to be recalculated right when leaving, that's why there is a
onBeforeUnmount
. From vuejs/router#350The text was updated successfully, but these errors were encountered: