javascript - 使用带有 ReactJS 的 axios 从响应 json 动态更新 img 的 src
问题描述
我使用图像对 ML 后端进行 axios post 调用,然后它处理并生成预测图像并将其保存到磁盘并返回新图像的名称。这些新图像的保存位置已经在后端预先设置。所以现在使用图像的名称,我想在反应中更新 img 的 src 属性。
const fd = new FormData();
fd.append('qqfile', files[0], files[0].name);
axios.post('http://localhost:5526/upload', fd)
.then(res => {
console.log(res.data.new_image);
var path = "/Documents//diabetic_detection/static/processed_file/"+res.data.new_image;
document.getElementById("result").src = ???
});
files[0] 是我发送到 api 的图像!res.data.new_image 是处理后图像的名称。我想用这个新图像动态更新 id 为“result”的 img 的 src。请帮忙
解决方案
推荐阅读
- r - 如何计算R中的轨迹长度
- c++ - Visual Studio 2019 C++ 桌面应用程序;如何制作子窗口?
- intellij-idea - IntelliJ 编辑器显示不正确的错误,使用 JavaFX
- python - Python:生成5个具有固定总和的随机整数(每个都有自己的范围)
- php - 即使有现有产品图像,如何在 WooCommerce 上设置默认产品缩略图?
- javascript - Google APi 客户端打开弹出窗口而不是重定向
- python - 如何确定不带空格的字符串中列表的匹配数?
- css - React - 如何在同一行对齐文本和img
- google-sheets - 如何删除谷歌表格中的空白行
- javascript - 有没有办法打开/关闭侧边栏