Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

using ´this´ inside axios

how can i use this inside axios?

example:

Don’t work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this.$axios.get("").then(function(response){ this.data = response.data })

Works

let handler = this
this.$axios.get("").then(function(response){ handler.data = response.data })

is it possible to use the first option?

>Solution :

You can, using an arrow function:

axios.get("").then(res => this.stuff = res.data)

This is because unlike regular anonymous functions, arrow functions don’t have a this context and use the lexical scope’s one

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading