updated
状态包含 true
或 false
,具体取决于自首次打开页面以来是否部署了新版本的应用。为了使其工作,你的 svelte.config.js
必须指定 kit.version.pollInterval
。
¥The updated
state contains true
or false
depending on whether a new version of the app has been deployed since the page was first opened. For this to work, your svelte.config.js
must specify kit.version.pollInterval
.
<script>
import { page, navigating, updated } from '$app/state';
</script>
<script lang="ts">
import { page, navigating, updated } from '$app/state';
</script>
版本更改仅发生在生产中,而不是在开发期间。因此,本教程中的 updated.current
将始终为 false
。
¥Version changes only happen in production, not during development. For that reason, updated.current
will always be false
in this tutorial.
你可以通过调用 updated.check()
手动检查新版本,而不管 pollInterval
如何。
¥You can manually check for new versions, regardless of pollInterval
, by calling updated.check()
.
{#if updated.current}
<div class="toast">
<p>
A new version of the app is available
<button onclick={() => location.reload()}>
reload the page
</button>
</p>
</div>
{/if}
在 SvelteKit 2.12 之前,你必须为此使用
$app/stores
,它为$updated
存储提供相同的信息。如果你目前正在使用$app/stores
,我们建议你迁移到$app/state
(需要 Svelte 5)。¥[!NOTE] Prior to SvelteKit 2.12, you had to use
$app/stores
for this, which provides an$updated
store with the same information. If you’re currently using$app/stores
, we advise you to migrate towards$app/state
(requires Svelte 5).
<h1>home</h1>
<p>this is the home page.</p>