Snippet:
export default {
data() {
return {
cityName: '',
}
},
methods: {
searchCity(event){
event.preventDefault()
fetchCityData().then(function(response) {
console.log(response)
this.cityName = response;
})
},
},
}
However, the line this.cityName = response; triggers an error Uncaught (in promise) TypeError: Cannot read properties of undefined
What is the correct way to handle data from asynchronous functions in Vue 3?