#Why script within `onMounted` cannot find DOM element during client rendering?

3 messages · Page 1 of 1 (latest)

wise harbor
#

I have a client component Map.client.vue that I want to render a map using Leaflet. Within this component, I have the necessary Leaflet code to render a map within the onMounted hook. However, Leaflet is throwing error because it cannot find the #map element that I defined in template.
When I change the onMounted hook to onUpdated, then it works, but that would rerender the map for every interaction with the page. I also try using client-only wrapper instead of the .client.vue extention, and that works.

Should the div#map element be available before the script within onMounted runs?

vestal smelt
wise harbor
#

It works!