How to pass headers on request with Vue.js 2

3

I need to pass the header Authorization which is located in localStorage with the key of iflix-user-token , here is my code:

getFilmes: function () {
    this.$http.get(Api.url + '/filme').then(
        response => {
            this.filmes = response.body
        }
    )
}

I'm using vue-resource .

    
asked by anonymous 22.10.2017 / 15:17

1 answer

1

Taking a look at the vue-resource documentation , you can pass headers like this:

getFilmes: function () {
    const token = localStorage.getItem('iflix-user-token');
    this.$http.get(Api.url + '/filme', {headers: {'Authorization': token}})
      .then(response => this.filmes = response.body);
}
    
22.10.2017 / 15:25