Vue GitHub user lookup I have made a small Vue app which fulfills the following user stories:

Given I make a search for an existing GitHub user, then:


The user's username is shown
The user's avatar is shown
The user's most commonly used language, if available, in their repositories is shown as a 'favourite language'
The user's followers, if there are any, are shown alongside their amount




Here is a working demo.

Here is my single file component:

&lt;template&gt;
  &lt;div id="app"&gt;
    &lt;form @submit.prevent="submit"&gt;
      &lt;input v-model="inputValue" type="text" placeholder="Enter a GitHub username..."&gt;
      &lt;button&gt;Go!&lt;/button&gt;
    &lt;/form&gt;
    &lt;h1 v-text="username"&gt;&lt;/h1&gt;
    &lt;img v-if="avatar" :src="avatar" class="avatar"&gt;
    &lt;h2 v-if="faveLang"&gt; Favourite Language: {{faveLang}} &lt;/h2&gt;
    &lt;h3 v-if="followers.length &gt; 0"&gt;Followers ({{followers.length}}):&lt;/h3&gt;
    &lt;ul v-if="followers.length &gt; 0"&gt;
      &lt;li v-for="follower in followers"&gt;
        {{follower}}
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import _ from 'lodash'

Vue.use(VueAxios, axios)

export default {
  name: 'app',

  data() {
    return {
      inputValue: '',
      username: '',
      avatar: '',
      followers: [],
      faveLang: '',
      urlBase: 'https://api.github.com/users',
    }
  },

  methods: {
    submit() {
      if (!!this.inputValue) {
        const api = `${this.urlBase}/${this.inputValue}`

        this.fetchUser(api)
      }
    },

    fetchUser(api) {
      Vue.axios.get(api).then((response) =&gt; {
        const { data } = response

        this.inputValue = ''
        this.username = data.login
        this.avatar = data.avatar_url

        this.fetchFollowers()
        this.fetchFaveLang()
      }).catch(error =&gt; {
        console.warn('ERROR:', error)
      })
    },

    fetchFollowers() {
      Vue.axios.get(`${this.urlBase}/${this.username}/followers`).then(followersResponse =&gt; {
        this.followers = followersResponse.data.map(follower =&gt; {
          return follower.login
        })
      })
    },

    fetchFaveLang() {
      Vue.axios.get(`${this.urlBase}/${this.username}/repos`).then(reposResponse =&gt; {
        const langs = reposResponse.data.map(repo =&gt; {
          return repo.language
        })

        // Get most commonly occurring string from array
        const faveLang = _.chain(langs).countBy().toPairs().maxBy(_.last).head().value()
        if (faveLang !== 'null') {
          this.faveLang = faveLang
        }
      })
    }
  }
}
&lt;/script&gt;

&lt;style&gt;
body {
    background-color: #daa520;
}

#app {
    display: flex;
    align-items: center;
    flex-flow: column;
    font-family: Comic Sans MS;
}

input {
    width: 320px;
}

input,
button {
    font-size: 25px;
}

h1 {
    font-size: 44px;
}

.avatar {
    height: 200px;
    width: 200px;
    border-radius: 10%;
}
&lt;/style&gt;


My questions:


Is this a good way of managing changing values, ie by mutating the data object? Or should this be represented in state?
How can I better structure this app? It could be split up into components but should it?
Is there a better way to make API calls like this, and should they go in the methods section?
Should the API calls be placed inside the mounted method?
This works. State works as well but you don't need it until your app gets more complex.
There are different ways to structure this app, but it doesn't necessarily make them better. I was able to grok this in just a few minutes, which is great. I was able to read it from top to bottom without jumping around the file, which is great. Your style is largely consistent throughout the app, which is great.


Points 3 and 4 are mostly the same as above. You can structure it differently, but it's not necessary for a small app like this. As the app grows you will notice some areas that can easily be refactored into their own pieces, and I think you've mentioned most of them.

Here are some ideas you can use as a learning exercise. Understanding them now will help you reason about larger apps in the future. They're not necessarily the correct way, just learning exercises:


Try using a component for the form and another for the stats. Think about how you would communicate the data between these two components.
Write unit tests to prove that your component(s) are working as expected. Currently you have a lot of logic in your component methods. Is it easy to test this logic with unit tests? Would it be easier to test this logic if it were separated from the controller?
Try extracting the API logic into another class that you can import. Currently your controller has data and methods that can be used by your template, but they are not. Think of these as 'public' properties and methods. Do they need to be public? Why would you not want to make them public?
Currently your methods are fetching data and then mutating the results. Try storing the raw data, and then use computed properties to alter the data for display. Does this approach make it easier or harder to reason about the logic? How does it affect the testability of your component?