Beck on and Djangofront on clean JS/HTML/CSS什么都没有,但font awesome没用过。
对于测试,我完全重新启动服务器并Ctrl+Shift+R重置静态文件的缓存。
有这样的方法代码init
init() {
document.addEventListener("DOMContentLoaded", async (event) => {
console.log(`UserOffice init`);
this.profile = await base.getProfile();
console.log(`UserOfficeProfile is ${this.profile}`);
...
});
}
方法代码getProfile
async getProfile() {
const profile = await this.getXHRasync(`${window.location.origin}/api/get_profile/`)[0];
console.log(`getProfile got ${profile}`)
return profile;
}
和方法代码getXHRasync
getXHRasync(path) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', path, true);
xhr.onload = function () {
console.log(`GET XHR 2, path is ${path}, and response ${xhr.responseText}`);
resolve(JSON.parse(xhr.responseText));
};
xhr.send();
});
}
我不是专家JS,我只需要重构。据我了解,我await必须等待该值,然后才能继续执行代码。
但是我得到的排气。
好像到处都记下来了async/await,可能我有什么不知道的地方,指正

尝试在 getProfile 代码中首先等待异步执行,然后按索引取值,否则结果是您从 Promise 中按索引取值。