3๐
โ
You cannot do
app.users = response.data.users;
Since app is not defined anywhere and your browsers console must be throwing an error, what are trying to do over here is assigning the users you have defined in data function.
That users object is present in current context and can be accessed through โthisโ keyword.
Try :
if(response.data.error){
this.errorMessage = response.data.message;
}
else{
this.users = response.data.users;
}
๐คVaibhav Singh
2๐
Thank you guys for your time I used your code but with little corrections
this is the final code that works
getAllUsers: function(){
axios.get('http://localhost:8888/vue-and-php/public/api/config.php?action=read', { crossdomain: true })
.then((response) => {
//console.log(response);
if(response.data.error){
this.errorMessage = response.data.message;
}else{
this.users = response.data.users;
}
});
}
๐คBeing MR.G
0๐
You probably want to set some information into your users
data field. You need to do something like:
if (response.data.error) {
this.errorMessage = response.data.message;
} else {
this.users = response.data.users;
}
Explanation: Vue reacts to changes in data
and props
. By doing this.users = response.data.users
, you are telling Vue that the users
have changed and then Vue will re-render based on how youโve used users
inside your template.
๐คArthur
Source:stackexchange.com