angularjs - 来自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 不是函数
解决方案
问题是它res
不是 Promise,你应该使用$q.resolve
它来将它转换为 Promise
推荐阅读
- bash - Cygwin bash shell 脚本抱怨
- android - 适用于 android 7 nougat 或更高版本的短信接收器
- html - 在 html 电子邮件中使用 python DIctionary 键值
- python - python:如何使用 pandas.read_sql_query 查询多个 mysql 数据库
- java - GUI 组织 5th BorderLayout
- modx - 如何配置 Wayfinder (ModX Revo) 以获取此输出
- sql - 从 sql 模块将 SQL 查询结果放入活动用户窗体上的对象中
- c++ - C++,尝试打印整数时 cout 的奇怪行为
- typescript - 如何使用打字稿中的查找来推断类型化的 mapValues?
- google-apps-script - Google Apps 脚本上的 API 错误