I wish to display data from my API request but it seems to be something wrong with something I can't figure out what it is... The data is not displaying on the page when I try to loop. And I get the data from the API via the postman. Please if anything is not explained correctly just write something...
This is my api.php Route::get('/user', 'Api\UserController@index');
This is the Api\UserController:
public function index()
{
return UsersResource::collection(User::all());
}
This is the vue script:
<script>
export default {
data: function () {
return {
users: [],
}
},
mounted() {
this.loadUsers();
},
methods: {
loadUsers: function () {
axios.get('api/user')
.then((response) => {
this.users= response.data.data;
})
.catch(function (error) {
console.log(error);
})
}
}
}
</script>
And this is the table i'm trying to put the data in:
<table >
<tr>
<th>
<div class="form-text">
TOP 10 USERS
</div>
</th>
<th>RATING</th>
<th>DEAL</th>
<th>LINK</th>
</tr>
<tr v-for="user in users" :key="user.id">
<td class="text-white">
{{user.name}}
</td>
<td>/5</td>
<td>% Discount</td>
<td>
<button class="btn buttonGlowGreen">VISIT</button>
</td>
</tr>
</table>