我正在执行 GET 请求以显示文档数据,虽然我收到 200并且有数据返回,但该函数的行为就像没有任何数据一样。我正在传递一个令牌,并且我相信它已正确传递,并且我没有在控制台中收到任何错误消息。
代码:
let _state = {isLoaded: false},
_dmsDocs,
// other things
// export default class and constructor are here
setToken(tkn){
_state.token = tkn;
if(_state.isLoaded != true) {
loadREST();
_state.isLoaded = true;
}
}
// this is where async function getDocumentData() is
async function loadREST(){
axios.get(`${_Something}/etc/GetAllDocs?DocNumber=00000`, {
withCredentials: true,
headers: {
accept: "Application/json;odata=verbose",
"Content-Type": "application/json",
"Authorization": _state.token
}
}).then(dms => {
if(dms.data && dms.data.length > 0) {
$(".docs .dms").removeClass("d-none");
$(".docs .msg").addClass("d-none");
_dmsDocs = dms.data;
getDocumentData(); // not hit
} else {
$(".docs .dms").addClass("d-none");
$(".docs .msg").removeClass("d-none").html("<h4>No Documents Found</h4>");
}
}).catch(err => {
console.log(err);
});
}
出于某种原因,_dmsDocs在我的观察列表中显示为“未定义”,我认为弄清楚这一点可能是我正在寻找的解决方案。除此之外,对于我的生活,我无法弄清楚为什么我的代码没有按预期运行。
这是调试器中代码的样子。您可以看到200和跳过函数调用的代码。:
这是 的片段_state.token,它显示了我的令牌的前几位:

