Answer the question
In order to leave comments, you need to log in
`
In which hook to call Axios to update the DOM?
Pulling data through Axios:
mounted() {
axios
.get(`http://api.openweathermap.org/data/2.5/find?lat=${this.lat}&lon=${this.lon}&type=like&lang=ru&units=${this.measureSystem}&APPID=${this.ApiKey}`)
.then(response => (this.dataWeather = response));
},
computed: {
setMeasure () {
if (this.toggle === 1) {
return this.measureSystem = 'metric'
} else {
return this.measureSystem = 'Imperial'
}
}
}
Answer the question
In order to leave comments, you need to log in
No hooks are needed here. Set up property tracking:
watch: {
measureSystem: {
immediate: true,
handler() {
// сюда переносите код из mounted - axios.get(...)
},
},
},
computed: {
measureSystem() {
return this.toggle === 1 ? 'metric' : 'Imperial';
},
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question