我需要等待对象中的必要更改才能完成该功能并将结果返回给调用者。但我想不出比使用“setInterval”更好的东西。我想我做错了。
async checkLockBox ({ state, dispatch, commit }, lockBox) {
if (lockBox.layers === 0) {
commit('lockBox', null);
return lockBox.result;
}
await commit('lockBox', lockBox);
return new Promise((resolve) => {
setInterval(async () => {
if (state.lockBox !== null) {
if (state.lockBox.layers === 0) {
await resolve(state.lockBox.result);
await commit('lockBox', null);
}
}
}, 100);
});
},