-1

how can i use this inside axios?

example:

Don't work

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?

1 Answers1

2

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

Vivick
  • 3,434
  • 2
  • 12
  • 25