reactjs - 如何在新选项卡上使用 axios 输出
问题描述
我想用户单击按钮,然后 Axios 输出将显示在新选项卡上(在 about:blank 或类似的地方)
公牛:
click() {
this.setState({ isLoading: true });
axios
.get(
`http://localhost:5000/model-list`
)
.then((res) => {
this.setState({
inferenceout: res.data , isLoading: false,
})
let newWin = window.open("about:blank", "res.data", "width=400,height=400");
newWin.document.write(JSON.stringify(res.data))
})
}
它目前在新选项卡中返回输出 JSON,但我希望我在下面编写的 HTML 脚本将在新选项卡中,请帮助我
解决方案
您要传递给新窗口的 HTML 元素是什么?
您可以在 JavaScript 中使用字符串插值来通过 HTML 元素传递数据,如下所示,
newWin.document.write(`<html><p>Whatever HTML you want and the ${res.data.name} you wanted</p></html>`)
如果您想要整个对象,您可以执行以下操作,
newWin.document.write(`<html><p>Whatever HTML you want and the ${JSON.stringify(res)}</p></html>`)
推荐阅读
- r - rep() 来自不同数据帧的行
- flutter - 首次登陆页面时停用 StreamBuilder
- python - 如何更新python selenium下载目录
- typescript - 来自“Typescript 中的评论”插件的 JSDoc 错误“描述不满足正则表达式模式”
- apache-kafka - Java客户端配置了单个Kafka代理IP和端口来连接,如果该代理在集群中关闭怎么办
- java - 在运行时并行编译java类
- spring - 事务隔离(不并发读取相同的数据)
- c# - 如何更改 CROSS APPLY 表达式中的 WHERE 子句
- javascript - 如何在量角器 E2E 中获取标题
- javascript - fullcalendar - “请在尝试导入插件之前导入顶级的 fullcalendar 库”