Reputation: 2018
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
Reputation: 6048
You have to call the fetchUsers
method. Call it in created
section.
created() {
this.fetchUsers();
}
Upvotes: 1