首页 > 解决方案 > 来自cookie angular js的令牌

问题描述

getToken() {

let res={};
let token = this.cookiesServices.getCookie("mobilecookie");
if(token){
   res.token=token;
  console.log("token-res",res);
  return res;
}else{
  return new this.httpUtils.POST(`${this.apiUrl2}authorization/token`);
}

getStoresCategories(mallId) { const res = this.getToken();

const defferd = this.$q.defer();
return res.then(dta => {
  const { token } = dta;
  const url = `${this.apiUrl2}stores/mall/${mallId}`;
  const conf = {
    headers: {
      Authorization: `bearer ${token}`,
      "Content-Type": "application/json",
      "Access-Control-Allow-Origin": "*"
    }
  };
  this.$http.get(url, conf).then(rsp => {
    defferd.resolve(rsp.data.data);
  });
  return defferd.promise;
});

}

缓存错误 TypeError: res.then 不是函数

标签: angularjscookiestoken

解决方案


问题是它res不是 Promise,你应该使用$q.resolve它来将它转换为 Promise


推荐阅读