我正在使用Promise进行获取请求。我无法使用请求中返回的JSON数组更新全局变量记录
app.js
class Token {
constructor(){
this.key = "some";
}
}
module.exports = new Token();
index.js
let My= require('./app')
setToken(){
return new Promise(resolve => {
this.getToken().then((data) => { //return key
if(data){
let gotToken = data;
My.key = gotToken.token
console.log(My.key) // print key
resolve(true);
}
})
});
}
in another function
console.log(My.key) // print some