Question:
I need to pass the Authorization
header which is located in localStorage
with the 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
.
Answer:
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);
}