
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
vue3-version-update
Advanced tools
vue3-version-update 是一个面向 Vue 3 管理后台与微前端子系统的运行时版本更新公共包。
它解决的是“前端如何发现新版本、如何以尽量不打断用户的方式提醒更新、以及用户确认后如何刷新到新版本”这件事。
Vue 3 项目vite-version-manifest 使用当前版本只保留 2 套正式方案:
anchor: 'header'
适用于有顶部导航栏的项目。
交互是“顶部入口 + 轻量卡片 Popover”。
anchor: 'right-edge'
适用于没有顶部栏,或者希望入口独立于页面布局存在的项目。
交互是“右侧拉手 + 一体式侧边更新面板”。
npm install vue3-version-update
import { initVersionUpdate } from 'vue3-version-update'
initVersionUpdate({
anchor: 'right-edge'
})
<template>
<VersionUpdateIndicator v-if="indicatorVisible" />
</template>
<script setup lang="ts">
import { VersionUpdateIndicator, useVersionUpdate } from 'vue3-version-update'
const { indicatorVisible } = useVersionUpdate()
</script>
如果项目使用 vite-version-manifest,当前版本信息通常会在开发与构建阶段自动注入,业务项目一般不需要手动传 runtimeEnv。
如果不是 Vite 项目,也可以手动传入运行时环境:
initVersionUpdate({
runtimeEnv: {
version: window.__APP_VERSION__,
buildId: window.__APP_BUILD_ID__,
buildTime: window.__APP_BUILD_TIME__,
baseUrl: '/'
}
})
initVersionUpdate(options?)初始化版本更新服务。
destroyVersionUpdate()销毁版本更新服务,清理轮询、聚焦监听、可见性监听。
适合微前端子系统卸载场景。
setVersionUpdateRuntimeEnv(runtimeEnv)动态设置当前运行环境版本信息。
refreshVersionUpdateTexts()当业务项目切换语言后,手动刷新当前文案。
useVersionUpdate()获取响应式状态和操作方法。
requestVersionUpdate()主动发起一次更新处理。
confirmVersionUpdate()直接确认并执行更新。
deferVersionUpdate(duration?)延后更新提醒。
默认使用当前配置的 remindDelay。
initVersionUpdate(options) 说明interface VersionUpdateOptions {
pollInterval?: number
remindDelay?: number
enableIndicator?: boolean
enableFocusCheck?: boolean
enableVisibilityCheck?: boolean
anchor?: 'header' | 'right-edge'
versionUrl?: string | (() => string)
storagePrefix?: string
refreshStrategy?: 'auto' | 'self' | 'top' | 'custom'
debug?: boolean
devMock?: boolean
timeFormatter?: (buildTime: string) => string
runtimeEnv?: {
version?: string
buildId?: string
buildTime?: string
baseUrl?: string
}
texts?: VersionUpdateTexts | (() => VersionUpdateTexts)
onUpdateDetected?: (context) => void | Promise<void>
onUpdateDeferred?: (context) => void | Promise<void>
onUpdateConfirmed?: (context) => void | Promise<void>
onRefresh?: (context) => void | Promise<void>
}
pollInterval
轮询间隔,默认 5 * 60 * 1000。
remindDelay
点击“稍后更新”后的默认冷却时间,默认 10 * 60 * 1000。
enableIndicator
是否显示更新入口。
enableFocusCheck
页面重新获得焦点时是否检查版本。
enableVisibilityCheck
页面从后台切回前台时是否检查版本。
anchor
默认展示方案。
初始化后,VersionUpdateIndicator 不传 anchor 时会自动使用这里的值。
versionUrl
版本清单地址,默认 version.json。
在 Wujie 等微前端场景下,组件会优先按子应用自己的运行地址解析该路径,而不是直接使用基座域名。
storagePrefix
本地存储前缀,用于隔离多项目缓存键。
refreshStrategy
刷新策略:
auto:独立运行刷新当前页,微前端场景刷新顶层页self:始终刷新当前页top:始终刷新顶层页custom:由 onRefresh 接管debug
是否输出调试日志。
devMock
是否启用开发环境 mock 预览能力。
开启后,访问 ?__mock_version_update=1 会继续请求 version.json,但运行时会临时伪造一个旧的本地构建标识,并拦截真实刷新,方便预览更新交互。
timeFormatter
自定义发布时间格式化函数。
适合把 ISO 时间转为本地展示格式,也适合接入业务项目自己的多语言时间格式化逻辑。
runtimeEnv
当前运行环境版本信息。
仅在未接入 vite-version-manifest,或需要手动覆盖运行环境时再传。
texts
自定义文案,支持对象或函数。
onUpdateDetected
检测到新版本时触发。
onUpdateDeferred
用户选择稍后更新时触发。
onUpdateConfirmed
用户确认立即更新时触发。
onRefresh
自定义刷新逻辑。
VersionUpdateIndicator 组件当前组件只支持两种展示方向:header、right-edge。
interface Props {
mode?: 'icon' | 'tag'
autoOpen?: boolean
showDeferOption?: boolean
showBuildTime?: boolean
showVersion?: boolean
deferOptionDuration?: number
anchor?: 'header' | 'right-edge'
sideTabText?: string
}
mode
顶部入口样式,仅在 anchor='header' 时有意义。
icon:图标入口tag:轻标签入口autoOpen
检测到新版本后,是否自动展开当前入口对应的面板。
showDeferOption
是否显示“2小时内不再提醒”选项。
默认 false。
showBuildTime
是否显示发布时间。
默认 false。
showVersion
是否显示版本号。
默认 false。
deferOptionDuration
勾选“2小时内不再提醒”时,实际写入的冷却时间。
anchor
展示方案:
headerright-edgesideTabText
右侧拉手文案,默认 待更新。
VersionUpdateIndicator 支持默认插槽自定义展示层。
<VersionUpdateIndicator v-slot="slotProps" anchor="header">
<button type="button" @click="slotProps.openPanel">
{{ slotProps.indicatorText }}
</button>
</VersionUpdateIndicator>
requestVersionUpdate
直接执行更新处理。
confirmVersionUpdate
直接确认更新。
deferVersionUpdate(duration?)
手动延后提醒。
openPanel
打开当前入口对应的更新面板。
closePanel
关闭更新面板。
panelVisible
当前面板是否已展开。
indicatorTitle
入口标题文案。
indicatorText
入口显示文案。
hasPendingUpdate
当前是否存在待更新版本。
indicatorVisible
当前入口是否可见。
latestVersion
当前检测到的最新版本号。可能为空。
latestBuildId
当前检测到的最新构建标识。
latestBuildTime
当前检测到的发布时间。可能为空。
remindAt
当前冷却截止时间戳。
useVersionUpdate() 返回值const {
initialized,
checking,
hasPendingUpdate,
indicatorVisible,
latestBuildId,
latestVersion,
latestBuildTime,
remindAt,
confirmText,
cancelText,
cardTitle,
cardMessage,
deferOptionText,
requestVersionUpdate,
confirmVersionUpdate,
deferVersionUpdate,
refreshVersionUpdateTexts
} = useVersionUpdate()
initVersionUpdate({
texts: () => ({
title: t('versionUpdate.title'),
message: t('versionUpdate.message'),
confirmText: t('versionUpdate.confirmText'),
cancelText: t('versionUpdate.cancelText'),
indicatorText: t('versionUpdate.indicatorText'),
indicatorTitle: t('versionUpdate.indicatorTitle'),
cardTitle: t('versionUpdate.cardTitle'),
cardMessage: t('versionUpdate.cardMessage'),
deferOptionText: t('versionUpdate.deferOptionText')
})
})
<VersionUpdateIndicator anchor="header" mode="icon" />
适用于常规后台布局。
<VersionUpdateIndicator anchor="right-edge" sideTabText="待更新" />
适用于地图、大屏、全屏页、无全局顶部栏项目。
initVersionUpdate({
refreshStrategy: 'self'
})
initVersionUpdate({
refreshStrategy: 'top'
})
说明:
vue3-version-update 会优先基于 $wujie.location 解析 version.jsonvite-version-manifest,这样运行时还能自动拿到 __APP_BASE_URL__version.json 仍然需要满足浏览器跨域要求;更稳的做法是让基座通过同域代理暴露一个 versionUrlinitVersionUpdate({
refreshStrategy: 'custom',
onRefresh() {
window.top?.location.reload()
}
})
{
"buildId": "2026.03.25-1001",
"version": "1.0.1",
"buildTime": "2026-03-25T10:01:00.000Z"
}
说明:
buildId 必填version 可选buildTime 可选因此当没有版本号或发布时间时,默认 UI 不会显示对应字段。
有效。它只抑制自动再次弹出,不会隐藏更新入口。
也就是说:
因为后台系统经常有表单、弹窗、编辑态,自动强刷容易导致用户数据丢失。当前包默认采用“发现更新后提示用户自主刷新”的策略。
当前包不负责:
version.jsonbuildId这些能力建议由 vite-version-manifest 和部署侧共同负责。
FAQs
Vue3 前端版本更新运行时公共包,统一处理版本探测、更新提示与待更新标识。
The npm package vue3-version-update receives a total of 37 weekly downloads. As such, vue3-version-update popularity was classified as not popular.
We found that vue3-version-update demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.