Background:
I’m building a web application using Vue 2 and Leaflet. I’m trying to share a single Leaflet map instance across multiple components in my application.
Issue:
I’m looking for a way to create a Leaflet map instance in one place and access and use it across multiple components in the entire application.
Code Example:
This is a method I have tried, but I don’t know if this way of writing is appropriate. Maybe there is a better way:
App.vue
provide() {
return {
parent: this
};
},
mounted() {
this.map = L.map('map',{})
}
components
inject: ["parent"]
Is there a more appropriate way?