[Resolvido] Erro "_axios2.default.get(...).this is not a function" quando dou um get por uma function no React

0 respostas
Mauro_Vaz_da_Silva

No meu backend tenho o seguinte codigo liberando os cors

module.exports = function(req, res, next){

res.header(Access-Control-Allow-Origin, *)

res.header(Access-Control-Allow-Methods, GET, POST, OPTIONS, PUT, PATCH, DELETE)

res.header(Access-Control-Allow-Headers, Origin, X-Requested-With, Content-type, Accept)

next()

}

ja no frontend fiz a seguinte função no arquivo do React

const URL=‘http://localhost:3003/api/todos

export default class Todo extends Component{

constructor(props){

super(props)

this.state = {description: ‘’, list: []}
this.handleAdd = this.handleAdd.bind(this)
    this.handleChange = this.handleChange.bind(this)
    
    this.refresh()
}

refresh(){
    axios.get(`${URL}?sort=-createdAt`)
        .this(res => console.log(resp.data))

    
}

quando abro o localhost fico com o seguinte erro:

app.js:35060 Uncaught TypeError: _axios2.default.get(…).this is not a function

Estou começando a aprender React e esse erro ta me travando, se alguém souber me ajudar, estarei agradecido, qualquer ajuda é bem vinda.

Criado 9 de janeiro de 2019
Respostas 0
Participantes 1