gpt4 book ai didi

reactjs - 将 window.print() 与 React 一起使用 - 在哪里调用它同时避免弃用警告

转载 作者:行者123 更新时间:2023-12-05 04:12:58 25 4
gpt4 key购买 nike

我在 React JS 应用程序中使用 window.print()。我希望在下载数据并呈现内容后触发打印模式。

在 Chrome 中,我在控制台中看到了这个警告:

Invoking 'print()' during microtask execution is deprecated and will be removed in M53, around September 2016. See https://www.chromestatus.com/features/5647113010544640 for more details.

我应该在哪里调用 window.print 以避免警告(以及最终弃用)?

最佳答案

调用api后出现一些错误是正常的,我不知道为什么Chrome团队计划禁止在微任务执行期间执行一些功能,如(alert,print,promt ..)。您可以通过将它放在 setTimeout 函数中来解决这个问题:

设置超时(函数(){
窗口打印();
}, 0)

关于reactjs - 将 window.print() 与 React 一起使用 - 在哪里调用它同时避免弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38938005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com