P粉2778243782023-08-16 10:20:51
Promise itself does not provide a method to pause execution, but you can use async/await syntax to achieve this. Create a custom Promise that resolves when the user clicks the "Continue" button. like this:
async function onFileSelected(event) { try { const response = await axios.post("") // 上传数据 await showModalAndWaitForUserInteraction() // 暂停并等待用户输入 await anotherMethod() // 用户交互后继续执行 // 继续执行剩余的Promise链 const anotherResponse = await axios.post("") // 提交更多信息到另一个终点 // ... } catch (error) { // 在这里处理错误 } } function showModalAndWaitForUserInteraction() { return new Promise((resolve) => { // 显示带有按钮的模态框 // ...模态框逻辑 // 然后 resolve() }) }