Trying to retrieve data from a URL using Axios in my Vue app is resulting in the error message:
Error: Arrow function should not return assignment
Complete error message:
Error: Arrow function should not return assignment (no-return-assign) at src\components\navbar.vue:123:13:
121 | created() {
122 | axios.get('http://ip-api.com/json')
> 123 | .then((response) => (this.countryCode = response.countryCode));
| ^
124 | },
125 | };
126 | </script>
1 error found.
The code snippet causing the issue:
<script>
import axios from 'axios';
export default {
name: 'navbarr',
data() {
return {
countryCode: null,
country: '',
countries: [
{ value: 'INT' },
{ value: 'UK' },
{ value: 'PT' },
{ value: 'US' },
{ value: 'FR' },
{ value: 'DE' },
{ value: 'IT' },
{ value: 'ES' },
{ value: 'IE' },
],
};
},
created() {
axios.get('http://ip-api.com/json')
.then((response) => (this.countryCode = response.countryCode));
},
};
</script>
Despite following official examples, I cannot figure out what's causing this issue!