[Vuejs]-Vue Resource – 401 (Unauthorized)

0👍

Vue resource get method signature looks like –

this.$http.get('/someUrl', [options]).then(successCallback, errorCallback);

You need to pass params along with the headers object.

this.$http.get('http://ppstemp.com/api/User/Profile', {
  params: {
    n: ...
  },
  headers: {
    "Authorization": "bearer " + localStorage.getItem('token'),
    "Accept": "application/json",
    "cache-control": "no-cache"
  }
}).then(
  (response) => {
    // Handle data returned
    console.log(response.data);
  },
  //error callback
  (err) => console.log(err));
}

Leave a comment