I have created a component for the user profile. JSON data is coming from Laravel JWT authentication. But getting
TypeError: Cannot read property 'id' of undefined. same for the name also
<template>
<div class="mt-3">
<div class="alert alert-danger" v-if="has_error">
<p>Something goes wrong</p>
</div>
<p>{{ user.id }}</p>
<p>{{ user.name }}</p>
</div>
</template>
<script>
export default {
data() {
return {
has_error: false,
user:{
id:'',
name:''
}
}
},
mounted() {
this.getUsers()
},
methods: {
getUsers() {
this.$http({
url: `auth/profile`,
method: 'GET'
})
.then((res) => {
this.user = res.data.user
}, () => {
this.has_error = true
})
}
}
}
</script>
Actual results must be: 1 Username
id- codervineres.data.useris what is causing trouble.console.log(res.data)and confirm you are receivinguserfrom the API. - Thomas Van der Veen