Skip to main content
基本 Svelte
介绍
反应性
属性
逻辑
事件
绑定
类和样式
动作
转换
高级 Svelte
高级反应性
重用内容
运动
高级绑定
高级转换
上下文 API
特殊元素
<script module>
后续步骤
基本 SvelteKit
介绍
路由
加载数据
标题和 cookie
共享模块
表单
API 路由
$app/state
错误和重定向
高级 SvelteKit
钩子
页面选项
链接选项
高级路由
高级加载
环境变量
结论

updated 状态包含 truefalse,具体取决于自首次打开页面以来是否部署了新版本的应用。为了使其工作,你的 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.

src/routes/+layout
<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().

src/routes/+layout

{#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).

上一页 下一页
1
2
3
<h1>home</h1>
<p>this is the home page.</p>