ristlin
120
2
Vue

Handling a data response object in Vue

Posted 2 months 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.

Reply to

Use Markdown with GitHub-flavored code blocks.