I have a basic openlayers map in a vue component:
<template>
<div id="map" style="width: 300px; height: 200px;"></div>
</template>
<script>
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import OSM from 'ol/source/OSM.js';
export default {
mounted() {
var map = new Map({
layers: [
new TileLayer({
source: new OSM(),
}),
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 2,
}),
});
},
};
</script>
Now I would like to reuse this component on multiple pages on my SPA, because I would like to avoid the tiles reloading and maintain features on the map. Normally (if not a map, but just general data) I could just remain the data state in a vuex store or alike, but since this openlayers object is bound to this specific 'map' div, I can´t see that it is possible. I´ve tried the vue element, but no luck. So how to get around this?