1 year ago

Handling a data response object in Vue

Posted 1 year ago by ristlin

I've been having issues handling the getResponse method in a component that uses a Vue2-Typeahead component. When my API returns a data object containing a single object, I can use the following:

getResponse: function(response) {
    return response.data.map(a => a.name);

However, if the data object contains more than one object I run into errors. I think I need to do something like below to correct it. I think the notation is not quite right though. Could I get some pointers? Thanks!

 getResponse: function(response) {
                var array = [];
                var test = response.data;
                forEach(test, array.push(test.name));
        return array;

Please sign in or create an account to participate in this conversation.