Dave
Dave

Reputation: 2018

Axios get method wont display any results

I am trying to grab user data from json file. I am using axios get method. It doesn't display anything on my page. It's just blank. Could anyone assist me?

.users(v-for="user in users")
    p {{ user.name }}

data ()  {
    return {
      users: []
    }
  },
  methods: {
    fetchUsers() {
      axios.get('https://jsonplaceholder.typicode.com/users')
      .then((response) => {
        const data = response.data;
        this.users = data
      })
      .catch((error) => {
        console.log(error);
      })
    }
  },

Upvotes: 0

Views: 115

Answers (1)

tuhin47
tuhin47

Reputation: 6048

You have to call the fetchUsers method. Call it in created section.

created() {
    this.fetchUsers();
  }

Upvotes: 1

Related Questions