Unable to retrieve values from Axios Response data

Unable to retrieve values from Axios Response data

Questions : Unable to retrieve values from Axios Response data

125
<script> export default { props: { id: Number, }, data () { return { password: null, loading: true, errored: false } }, created () { axios .get('http://localhost:3000/users?filter[where][id]=' + this.id) .then(response => { this.password = response.data.password }) .catch(error => { console.log(error) this.errored = true }) .finally(() => this.loading = false) } } </script> 

The above is the code in question, i’m in4codes_vue.js simply trying to retrieve a current user’s in4codes_vue.js password as plain text. (It’s for a in4codes_vue.js University Project, and I need to display in4codes_vue.js the user’s password hash as text to prove in4codes_vue.js it’s hashed).

The above code will return this array in dev in4codes_vue.js tools:

[ { "id": 1, "user": "SomeUsername", "password": "SomePasswordHash" } ] } 

However, If I run that code as whole, it in4codes_vue.js will not return anything when using:

{{ this.password }} 

I have no idea why this is.

Edit:

If I change password to info, and then in4codes_vue.js this.info = response.data, then access that in4codes_vue.js array via this.info[0].password it works, in4codes_vue.js however when I refresh I’ll get this error: in4codes_vue.js Cannot read properties of null (reading in4codes_vue.js ‘0’).

Total Answers 0