点击保存后接口调用顺序问题
在点击保存后提交表单时,程序需要同时调用新增和上传接口。然而,在第一时间调用新增接口时,它无法获得上传图片的值。为了解决此问题,添加了 setTimeout。
更优的解决方法是:
修改后的代码示例:
uploadImg(formData, 'customer').then(response => { this.fileInModel.content = response.data[0].url; this.add(response.data[0].url); });
或者:
async add() { const response = await uploadImg(formData, 'customer'); this.fileInModel.content = response.data[0].url; this.submit(); }
以上就是点击保存后上传和新增接口调用顺序如何优化?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号