Can someone assist me? I am attempting to retrieve an object response from an API using axios in an async function with try and catch blocks. Currently, when I make the request, I receive: Promise { pending }. How can I access my object?
Here is a snippet of the template:
<div class="div-search-city">
<input v-model="inputCity" placeholder="insert city name"/>
<button id="buttonCity" @click="get()">Search city</button>
</div>
And here is part of the script:
<script>
import myFunction from './js/service.js';
export default {
name: 'Input',
data () {
return {
myData: {}
}
},
methods: {
get(){
this.myData = myFunction.axiosRequest(this.inputCity);
console.log(this.myData);
}
}
}
</script>
Additionally, this excerpt shows the contents of my service.js file:
const axios = require('axios');
var myFunctions = {
async axiosRequest(city){
var options = {
method: 'GET',
url: 'https://api.waqi.info/feed/' + city + '/',
params: {
token: 'a1d2e0ee074e48f8bf....................'
}
};
try {
let response = await axios.request(options);
return response
}catch (error) {
console.error(error)
}
}
}
export default myFunctions
Thank you for your help.