setInterval不起作用而没有错误

发布于 2025-02-12 20:01:52 字数 1488 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的背包 2025-02-19 20:01:52

在您的setInterval中,您正在执行函数并将其返回值作为参数传递,而不是将函数本身传递为参数。
应该是:

const handle = setInterval(scrape, 4000);

请注意,您不会在功能内使用,因为它将在setInterval范围内进行调用。
如果您需要使用,请使用bind()

const handle = setInterval(scrape.bind(scrape), 4000);

In your setInterval you are executing the function and passing it's return value as argument, instead of passing function itself as argument.
It should be:

const handle = setInterval(scrape, 4000);

Note, you won't be use this inside the function, because it will be called inside setInterval scope.
If you need to use this, then use bind():

const handle = setInterval(scrape.bind(scrape), 4000);
世界如花海般美丽 2025-02-19 20:01:52

您似乎在两个地方称为“ scrape()”方法。一旦进入setInterval()方法,然后立即在线路上再次在线上。看起来像你的问题。

You seem to be calling the "scrape()" method in two places. Once in the SetInterval() method and then immediately again on the line after. That looks like your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文