关于 vueuse-core-skilld
vueuse-core-skilld 是关于 @vueuse/core 15.0.0 的开发技能资料,面向使用 Vue 组合式函数的开发者。它整理常见浏览器与响应式功能、v15 行为变化及迁移注意事项,并包含 useWebMCP 示例。
主要功能
- 01本地存储、主题与标题管理
- 02节流及可配置调度器
- 03WebSocket 与事件源处理
- 04useWebMCP 工具注册
- 05v14 到 v15 迁移注意事项
适用场景
- 01保存并合并本地设置
- 02根据状态动态更新页面标题
- 03控制定时或动画帧任务
- 04为浏览器 Agent 注册 WebMCP 工具
MCP 相关
资料展示了 useWebMCP 示例,用于向浏览器 Agent 注册 WebMCP 工具。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ skilld-dev/ vue-ecosystem-skills --skill vueuse-core-skilld安装后在 Claude Code 中输入/vueuse-core-skilld确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/api-surface.mdbest-practice.mdmigration-v15.mdnew-functions-v15.mdshared-api.md详细介绍
@vueuse/core 15.0.0
准备好的源代码:@vueuse/[email protected](package.json:4)。以下文件引用使用相对于该包根目录的路径。文档引用为绝对 URL。
环境限制
- 自 v13 起仅支持 ESM(
"type": "module",package.json:3)。require()会失败。 - 需要 Vue
^3.5.0(package.json:42)。 - 需要 Node.js
>= 22(package.json:39);v15.0.0 起不再支持 Node 20(发布说明)。 - 导出:
.和./metadata(package.json:24-28)。所有内容均从dist/提供。 @vueuse/[email protected]是一个依赖项,并且已完整重新导出(dist/index.d.ts:3),因此import { useToggle } from '@vueuse/core'可以正常使用;请参阅共享 API。
会改变生成代码的 v15 规则
- 不再有
templateRef。 已在 v15.0.0 中移除(发布说明)。请改用 Vue 内置的useTemplateRef()。 - 定时器选项已移除;请传入
scheduler。 v15.0.0 中,ConfigurableScheduler组合式函数已移除弃用的逐个组合式函数的interval/immediate选项(发布说明)。受影响的选项接口会扩展或交叉组合ConfigurableScheduler(dist/index.d.ts:212-217):useCountdown、useNow、useTimestamp、useTimeAgo、useTimeAgoIntl、useTemporalNow、useElementByPoint、useMemory、useVibrate,以及useWebSocket的heartbeat选项。scheduler的类型为(cb: Fn) => Pausable,因此可以直接接入useRafFn。 useThrottleFn现在默认会触发尾随调用(trailing的默认值从 false 改为 true,v15.0.0(发布说明))。传入trailing = false(第 3 个参数)即可保持 v14 的行为。useEventSource会处理 SSEmessage事件,并同时触发onmessage和addEventListener处理程序(v15.0.0(发布说明))。对于未命名事件,请勿手动添加重复监听器。- 下一个主版本将更改
deepRefs的默认值。 目前默认值为true,并明确警告下一个主版本会将其改为false(dist/index.d.ts:204-211)。如果该值很重要,请显式传入deepRefs。
请勿使用(已弃用或已替换)
| 导出项 | 替代方案 | 依据 |
|---|---|---|
computedEager | computed()(Vue 3.4+ 在值未改变时不再重新触发) | 文档“将在未来版本中移除” |
watchPausable | Vue 3.5 原生 watch() 会返回 { stop, pause, resume } | 文档 |
executeTransition | transition(source, from, to, options) | 在 dist/index.d.ts:5114-5121 中标记为已弃用 |
UseTransitionOptions.transition | easing 选项 | 同一弃用代码块 |
breakpointsVuetify | breakpointsVuetifyV2 或 breakpointsVuetifyV3 | 在 dist/index.d.ts:758-762 中标记为已弃用 |
asyncComputed | computedAsync(别名仍保留,dist/index.d.ts:46) | computedAsync 的别名 |
常见任务
import { useLocalStorage, useDark, useTitle, useThrottleFn } from '@vueuse/core'
// Reactive getter args enable derived values without computed()
const isDark = useDark()
const title = useTitle(() => isDark.value ? 'Night' : 'Day')
// Storage with schema evolution: mergeDefaults fills new keys
const settings = useLocalStorage('settings', { theme: 'light', density: 'comfortable' }, { mergeDefaults: true })
// v15 throttle fires a trailing call by default; 3rd arg is `trailing`
const onResize = useThrottleFn(handler, 200, false, true) // trailing=false, leading=true
import { useWebMCP } from '@vueuse/core'
// Register a WebMCP tool for browser agents (new in v15)
const { isSupported, isRegistered, error } = useWebMCP({
name: 'get-current-user',
description: 'Returns the signed-in user id',
inputSchema: { type: 'object' },
execute: () => ({ userId: user.value?.id ?? null }),
})
更多模式:最佳实践。
参考资料
- API 概览:完整的 v15 导出清单,按类别分组。
- 共享 API:由 core 重新导出的
@vueuse/shared函数。 - v14 到 v15 迁移:自 v14.3.0 起所有不兼容变更、功能和重要修复,均附有引用。
- v15 新增函数:
useWebMCP、useTemporalNow、useLiveAnnouncer、useElementOverflow的用法。 - 最佳实践:getter、事件过滤器、存储序列化器、调度器、SSR、作用域。
调试说明(v15 修复可能解释行为变化)
useFetch会忽略较新请求启动后返回的过时成功响应,并会忽略重新获取成功后返回的过时中止错误 (v15, v14.4)。useWebSocket会忽略来自已被替代套接字的消息,并在显式调用close()后将状态同步为CLOSED(同上版本)。useResizeObserver使用instanceof Element检查来保护observe(),因此 Vue 注释节点不再导致崩溃(v15)。- 指针处理:
useDraggable和usePointerSwipe会在pointercancel时结束,usePointer会重置isInside,onLongPress会清除待处理的按压 (v15, v14.4)。
评论
支持 Markdown