Closed maninak closed 3 years ago
Hi @maninak
Thanks for the detailed issue. Can you provide a minimal reproduction example as well? It's rather difficult to pinpoint the source of the problem from the example you provided.
Hey @HusamIbrahim
I've prepared a code-sandbox for you as requested: https://codesandbox.io/s/adoring-chaplygin-w07rm?file=/src/StationsMap.vue
You may need to hit that reload button once if the gmaps api-key won't work first try
On StationsMap.vue
, line 28 I have a comment. Whatever is the default prop value is what will be used for the markers, even if it is updated later.
Also notice I'm using vue3-google-map@0.5.1
because of https://github.com/inocan-group/vue3-google-map/issues/13
Hey there, folks! Is there any update on this issue? Anything else I can do to help accelerate it?
If somebody could have a look and help me solve this within the next 1-2 weeks, it would be a MASSIVE help! :pray:
Apologies @maninak this is still pending. I've had a look at the example you provided but the cause of the issue isn't immediately obvious to me and unfortunately I have little time these days for anything other than a quick fix. If you think you can provide a more minimal example that can highlight the issue more clearly please do share.
@maninak I've had a second look at the sandbox you provided and I'm not sure if it's an accurate representation of your issue. The non-reactivity in the sandbox is due to the use of a normal function for the setTimeout
callback instead of an arrow function. See this fixed version:
https://codesandbox.io/s/unruffled-bas-j8ly8
Hey, thank you for looking back into it.
I found the issue and it was on my side! As I suspected I was using the composition API wrong.
In BaseMap.svg
(as shown in OP) in setup
I'm exposing the props like so, in order to have access to them in the template:
return {
googleMapCmp,
GOOGLE_MAPS_CONFIG,
center: props.center, // <-- oops!
markers: props.markers, // <-- oops!
zoom,
centerMapToPosition,
}
}
I remember distinctly how this "smelled" back then and I struggled with accepting it, but I also remember that the latest vue3 version at the time seemed to not expose the props
to the template automatically (which seemed really weird), unless I returned them from setup
.
Soon after I let that issue be, I upgraded vue and found out in other components that I could use the props directly, but totally forgot about refactoring this BaseMap
nor that this would fix my problem. Until today! (your comment jolted me into it)
Removing the marked lines fixed my reactivity problem (duh!).
Thank you for your time and sorry for the hassle.
No worries and glad you could resolve your issue. I'm still learning about the composition API myself so thank you for pointing out that gotcha.
Hello folks,
Is this a bug or am I using the composition API wrong here (I'm new with it)?
I have a
BaseMap.vue
component which is initially rendered the[]
as the value of the propmarkers
and when the backend responds that prop is value is updated with a (new) populated array.Here's my BaseMap.vue:
and the wrapping component StationsMap.vue:
Expectation:
options
prop in<Marker>
renders new markersActual:
Additional info:
BaseMap.vue
because the map will zoom in and center around where the markers are expected to render (so the watcher triggers)BaseMap.vue
component (note the prop already has value at this point since the wrapping componentStationsMap.vue
has already received the BE response) by making any irrelevant code change the markers will render as expected. Effectively this emulates the hardcoded case.vue3-google-map@0.5.1
because of https://github.com/inocan-group/vue3-google-map/issues/13Thanks for all the help!!