Closed
Description
I have an app that has Leaflet map in different pages, and customer wants the view must be synced. I tried to make the center of the map and at least the zoom sync but had no luck.
Let's say I have simple leaflet map:
<l-map
:center="currentCenter"
:zoom="currentZoom"
:options="mapOptions"
:url="url"
/>
In computed, I tried this way:
computed: {
currentCenter: {
get() {
return this.$store.state.currentCenter;
// try to get currentCenter from vuex store
},
set(value) {
this.$store.commit('updateCenter', value);
// this setter does not triggered when currentCenter changes.
}
}
}
My problem is, it can get correct currentCenter when mounted, but whenever I pane the map around, the Leaflet map change the currentCenter, but the setter inside currentCenter does not triggered, so vuex yelling "Do not mutate vuex store state outside mutation handlers."
So my question is, how could I can make the setter in currentCenter computed get triggered everytime I pane the leaflet map?
Thank you.
Versions
- Leaflet: v1.3.1
- Vue: v2.5.13
- Vue2Leaflet: v1.0.2
Metadata
Metadata
Assignees
Labels
No labels