I have some HTML tag with prop options
that gets an array. The prop looks like :options="getOptions(param)"
. The functions looks like:
getOptions: function(param) {
var queryArray = [];
var url;
// Logic to build queryArray
url = '/' + this.collection_name + '/params/' + param + '?' + queryArray.join('&');
let promiseResponse = this.getRequest(url);
console.log(promiseResponse);
return promiseResponse;
},
getRequest: (url) => {
return axios.get(url).then(response => {
return response.data
});
}
The URL that is being generated in getOptions
and being passed to getRequest
contains an array of options like so: [option1,option2]
. I can see a Promise
object is being printed to the console but I need it to return the actual data. This is why I used response.data
. I also tried to use async
and await
in some variants like as it said in this post How do I return the response from an asynchronous call?:
getRequest: async (url) => {
return axios.get(url).then(response => {
return response.data
});
},
It didn't work and I'm not sure that I fully committed to use async
or await
because in the docs it said that:
async/await
is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.
How can I make getOptions
return an array of the options?