I'm building a vue and leaflet application and I keep getting this error.
[Vue warn]: Property or method "markers" is not defined on the instance but referenced during render.
I can't find the problem, both the names in the variable and the code are spelled correctly and they are all in the same component.
(note: this is not a duplicate of [Vue warn]: Property or method is not defined on the instance but referenced during render as mine is in a single file component and also the answers there didn't help me)
here is my code
<template>
<div class="containerTest">
<div style="height: 80vh">
<LMap :zoom="zoom" :center="center">
<LTileLayer :url="url"></LTileLayer>
<l-marker
:key="index"
v-for="(brew, index) in markers"
:lat-lng="latLng(brew.latitude, brew.longitude)"
></l-marker>
<!-- <LMarker :lat-lng="[47.413220, -1.219482]"></LMarker>
<LMarker :lat-lng="[46.193220, 4.82]"></LMarker>
<LMarker :lat-lng="[45.193220, 6.82]"></LMarker>
<LMarker :lat-lng="[47.03220, -0.9482]"></LMarker>
<LMarker :lat-lng="[46.03220, 2.9482]"></LMarker> -->
</LMap>
</div>
</div>
</template>
<script>
import { LMap, LTileLayer, LMarker } from "vue2-leaflet";
export default {
name: "Map",
data: function () {
return {
markers: []
}
},
components: {
LMap,
LTileLayer,
LMarker
},
data() {
return {
url: "https://api.maptiler.com/maps/streets/{z}/{x}/{y}.png?key=CFmlXsYmVozAdWKEtdT5",
zoom: 6,
center: [46.5322, 2.9482],
bounds: null
};
},
mounted: function () {
fetch('https://api.openbrewerydb.org/breweries').then((response) => {
return response.json();
}).then(json=>{
this.brews = json
console.log(this.brews)
})
},
methods: {
latLng: function(lat, lng) {
return L.latLng(lat,lng);
},
}
};
</script>