Answer the question
In order to leave comments, you need to log in
How to repeat this code in case of request error?
The request is sent to created() , then when the response is received in mounted() , it performs the necessary actions on a successful response - the question is, how can I repeat the request and do the same actions on a failed request? Tell me how to do it?
created(){
this.dataRequest = this.getAllData()
},
mounted() {
this.markers = DG.featureGroup();
this.popups = DG.featureGroup();
this.map = DG.map("map", {
center: [54.98, 82.89],
zoom: 9,
minZoom: 7,
zoomControl: false,
fullscreenControl: false
});
this.dataRequest.then(response => {
this.filter() // для планировок экшен
this.setMarkers(this.residentials)
this.map.on("zoomstart", this.onZoomStart);
this.map.on("zoomend", this.onZoomEnd);
})
.catch(error => {
console.log(error);
});
},
Answer the question
In order to leave comments, you need to log in
Make a separate method like fetchData(). Call it on mounted.
fetchData() {
this.dataRequest.then(response => {
this.filter() // для планировок экшен
this.setMarkers(this.residentials)
this.map.on("zoomstart", this.onZoomStart);
this.map.on("zoomend", this.onZoomEnd);
})
.catch(error => {
this.fetchData();
});
}
mounted() {
this.markers = DG.featureGroup();
this.popups = DG.featureGroup();
this.map = DG.map("map", {
center: [54.98, 82.89],
zoom: 9,
minZoom: 7,
zoomControl: false,
fullscreenControl: false
});
await fetchData();
this.setMapMarkets();
},
methods: {
setMapMarkers() {
this.filter() // для планировок экшен
this.setMarkers(this.residentials)
this.map.on("zoomstart", this.onZoomStart);
this.map.on("zoomend", this.onZoomEnd);
},
async fetchData() {
try {
const response = await this.dataRequest();
// как-то надо использовать response, но у вас нет использования
} catch (e) {
// if ошибка сети
await this.fetchData()
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question