有没有办法使用 SvelteKit 每 10 秒刷新一次页面?我必须刷新页面才能从端点获取输出。
src/routes/[id].svelte从加载数据src/routes/[id].ts。
要刷新端点,您可以在页面路由中使用 invalidate 。
import { onDestroy } from "svelte";
import { invalidate } from "$app/navigation";
export your_end_point_prop;
// resfresh your_end_point_prop
const apiInterval = setInterval(async () => {
await invalidate("/your_endpoint");
}, 1000000);
... code to handle your end_point_prop
onDestroy(() => {
clearInterval(apiInterval);
});
Run Code Online (Sandbox Code Playgroud)
Tem*_*pus -2
我在 onMount 内部调用了 setInterval(/* 获取代码 */)
| 归档时间: |
|
| 查看次数: |
11871 次 |
| 最近记录: |