[Vuejs]-Populating Vue data based on response from axios GET request

3👍

I don’t see anything wrong with this. It’s much cleaner to just assign it though, since you’re only getting the images once in the mounted hook.

export default {
    data: function() {
        return {
            images: []
        }
    },
    mounted() {
        axios.get('https://api.unsplash.com/photos/?client_id=secret')
        .then(response => {
            this.images = response.data;
        })
        .catch((error) => console.log(error));
    }
}

Leave a comment