I cannot get or display data from an API but the API is working fine when I console.log the issue. but I cannot display data in my table I used v-for I am new to Vue.js I don't know how to solve this issue
I am using Vue.js 2, Axios method to connect to my API
here's my code
import axios from 'axios'
export default{
data(){
return{
errorMessage: "",
successMessage: "",
users: []
}
},
mounted: function(){
this.getAllUsers();
},
methods:{
getAllUsers: function(){
axios.get('http://localhost:8888/vue-and-php/public/api/config.php?action=read', { crossdomain: true })
.then(function(response){
//console.log(response);
if(response.data.error){
app.errorMessage = response.data.message;
}else{
app.users = response.data.users;
}
});
}
}
}
THIS IS WHERE I WANT TO DISPLAY MY DATA
<!--test PHP-->
<button class="fright addNew btn-sm btn-success" data-toggle="modal" data-target="#exampleModalLong">Add New</button>
<p class="errorMessage alert alert-danger" v-if="errorMessage">
{{errorMessage}}
</p>
<p class="successMessage alert alert-success" v-if="successMessage">
{{successMessage}}
</p>
<table class="table">
<tr>
<th>ID</th>
<th>User Name</th>
<th>Name</th>
<th>Email</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<tr v-for="user in users">
<td>{{user.id}}</td>
<td>{{user.username}}</td>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td><button class="btn btn-sm btn-success">ADD</button></td>
<td><button class="btn btn-sm btn-danger">DELETE</button></td>
</tr>
</table>
app.users? I would expectthis.users...response.data.message?