@dianzhong/create-harness-app 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/index.mjs +412 -0
  2. package/package.json +29 -0
  3. package/templates/axios/.env.example +2 -0
  4. package/templates/axios/src/api/auth.ts +19 -0
  5. package/templates/axios/src/api/request.ts +61 -0
  6. package/templates/axios/src/types/api.ts +26 -0
  7. package/templates/axios/src/utils/auth.ts +5 -0
  8. package/templates/axios/src/utils/storage.ts +17 -0
  9. package/templates/harness/full/.agents/skills/find-skills/SKILL.md +143 -0
  10. package/templates/harness/full/.agents/skills/vue-best-practices/LICENSE.md +21 -0
  11. package/templates/harness/full/.agents/skills/vue-best-practices/SKILL.md +155 -0
  12. package/templates/harness/full/.agents/skills/vue-best-practices/SYNC.md +5 -0
  13. package/templates/harness/full/.agents/skills/vue-best-practices/references/animation-class-based-technique.md +258 -0
  14. package/templates/harness/full/.agents/skills/vue-best-practices/references/animation-state-driven-technique.md +287 -0
  15. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-async.md +99 -0
  16. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-data-flow.md +313 -0
  17. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-fallthrough-attrs.md +179 -0
  18. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-keep-alive.md +139 -0
  19. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-slots.md +226 -0
  20. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-suspense.md +231 -0
  21. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-teleport.md +110 -0
  22. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-transition-group.md +131 -0
  23. package/templates/harness/full/.agents/skills/vue-best-practices/references/component-transition.md +135 -0
  24. package/templates/harness/full/.agents/skills/vue-best-practices/references/composables.md +303 -0
  25. package/templates/harness/full/.agents/skills/vue-best-practices/references/directives.md +168 -0
  26. package/templates/harness/full/.agents/skills/vue-best-practices/references/perf-avoid-component-abstraction-in-lists.md +177 -0
  27. package/templates/harness/full/.agents/skills/vue-best-practices/references/perf-v-once-v-memo-directives.md +185 -0
  28. package/templates/harness/full/.agents/skills/vue-best-practices/references/perf-virtualize-large-lists.md +182 -0
  29. package/templates/harness/full/.agents/skills/vue-best-practices/references/plugins.md +178 -0
  30. package/templates/harness/full/.agents/skills/vue-best-practices/references/reactivity.md +371 -0
  31. package/templates/harness/full/.agents/skills/vue-best-practices/references/render-functions.md +227 -0
  32. package/templates/harness/full/.agents/skills/vue-best-practices/references/sfc.md +355 -0
  33. package/templates/harness/full/.agents/skills/vue-best-practices/references/state-management.md +138 -0
  34. package/templates/harness/full/.agents/skills/vue-best-practices/references/updated-hook-performance.md +193 -0
  35. package/templates/harness/full/.claude/agents/code-reviewer.md +109 -0
  36. package/templates/harness/full/.claude/agents/harness-reviewer.md +51 -0
  37. package/templates/harness/full/.claude/hooks/guard-tool.cjs +234 -0
  38. package/templates/harness/full/.claude/hooks/notify.cjs +168 -0
  39. package/templates/harness/full/.claude/hooks/quality-gate.cjs +135 -0
  40. package/templates/harness/full/.claude/rules/delivery.md +66 -0
  41. package/templates/harness/full/.claude/rules/formatting.md +7 -0
  42. package/templates/harness/full/.claude/rules/git.md +8 -0
  43. package/templates/harness/full/.claude/rules/skills-mcp.md +13 -0
  44. package/templates/harness/full/.claude/rules/vue.md +227 -0
  45. package/templates/harness/full/.claude/settings.json +123 -0
  46. package/templates/harness/full/.claude/skills/find-skills/SKILL.md +143 -0
  47. package/templates/harness/full/.claude/skills/vue-best-practices/LICENSE.md +21 -0
  48. package/templates/harness/full/.claude/skills/vue-best-practices/SKILL.md +155 -0
  49. package/templates/harness/full/.claude/skills/vue-best-practices/SYNC.md +5 -0
  50. package/templates/harness/full/.claude/skills/vue-best-practices/references/animation-class-based-technique.md +258 -0
  51. package/templates/harness/full/.claude/skills/vue-best-practices/references/animation-state-driven-technique.md +287 -0
  52. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-async.md +99 -0
  53. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-data-flow.md +313 -0
  54. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-fallthrough-attrs.md +179 -0
  55. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-keep-alive.md +139 -0
  56. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-slots.md +226 -0
  57. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-suspense.md +231 -0
  58. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-teleport.md +110 -0
  59. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-transition-group.md +131 -0
  60. package/templates/harness/full/.claude/skills/vue-best-practices/references/component-transition.md +135 -0
  61. package/templates/harness/full/.claude/skills/vue-best-practices/references/composables.md +303 -0
  62. package/templates/harness/full/.claude/skills/vue-best-practices/references/directives.md +168 -0
  63. package/templates/harness/full/.claude/skills/vue-best-practices/references/perf-avoid-component-abstraction-in-lists.md +177 -0
  64. package/templates/harness/full/.claude/skills/vue-best-practices/references/perf-v-once-v-memo-directives.md +185 -0
  65. package/templates/harness/full/.claude/skills/vue-best-practices/references/perf-virtualize-large-lists.md +182 -0
  66. package/templates/harness/full/.claude/skills/vue-best-practices/references/plugins.md +178 -0
  67. package/templates/harness/full/.claude/skills/vue-best-practices/references/reactivity.md +371 -0
  68. package/templates/harness/full/.claude/skills/vue-best-practices/references/render-functions.md +227 -0
  69. package/templates/harness/full/.claude/skills/vue-best-practices/references/sfc.md +355 -0
  70. package/templates/harness/full/.claude/skills/vue-best-practices/references/state-management.md +138 -0
  71. package/templates/harness/full/.claude/skills/vue-best-practices/references/updated-hook-performance.md +193 -0
  72. package/templates/harness/full/.editorconfig +8 -0
  73. package/templates/harness/full/.husky/commit-msg +1 -0
  74. package/templates/harness/full/.husky/pre-commit +1 -0
  75. package/templates/harness/full/.lintstagedrc.json +4 -0
  76. package/templates/harness/full/.nvmrc +1 -0
  77. package/templates/harness/full/.oxlintrc.json +11 -0
  78. package/templates/harness/full/.prettierrc.json +6 -0
  79. package/templates/harness/full/AGENTS.md +3 -0
  80. package/templates/harness/full/CLAUDE.md +28 -0
  81. package/templates/harness/full/GEMINI.md +3 -0
  82. package/templates/harness/full/commitlint.config.ts +3 -0
  83. package/templates/harness/full/docs/ai-harness.md +77 -0
  84. package/templates/harness/full/docs/delivery-template.md +66 -0
  85. package/templates/harness/full/docs/git.md +24 -0
  86. package/templates/harness/full/docs/harness-quick-reference.md +89 -0
  87. package/templates/harness/full/docs/review-checklist.md +49 -0
  88. package/templates/harness/full/scripts/harness-hooks.test.mjs +218 -0
  89. package/templates/harness/full/scripts/verify-skills.mjs +248 -0
  90. package/templates/harness/full/scripts/verify-skills.test.mjs +72 -0
  91. package/templates/harness/full/skills-lock.json +50 -0
  92. package/templates/harness/minimal/.claude/hooks/guard-tool.cjs +234 -0
  93. package/templates/harness/minimal/.claude/hooks/quality-gate.cjs +135 -0
  94. package/templates/harness/minimal/.claude/settings.json +27 -0
  95. package/templates/harness/minimal/CLAUDE.md +12 -0
@@ -0,0 +1,179 @@
1
+ ---
2
+ title: Component Fallthrough Attributes Best Practices
3
+ impact: MEDIUM
4
+ impactDescription: Incorrect $attrs access and reactivity assumptions can cause undefined values and watchers that never run
5
+ type: best-practice
6
+ tags: [vue3, attrs, fallthrough-attributes, composition-api, reactivity]
7
+ ---
8
+
9
+ # Component Fallthrough Attributes Best Practices
10
+
11
+ **Impact: MEDIUM** - Fallthrough attributes are straightforward once you follow Vue's conventions: hyphenated names use bracket notation, listener keys are camelCase `onX`, and `useAttrs()` is current-but-not-reactive.
12
+
13
+ ## Task List
14
+
15
+ - Access hyphenated attribute names with bracket notation (for example `attrs['data-testid']`)
16
+ - Access event listeners with camelCase `onX` keys (for example `attrs.onClick`)
17
+ - Do not `watch()` values returned from `useAttrs()`; those watchers do not trigger on attr changes
18
+ - Use `onUpdated()` for attr-driven side effects
19
+ - Promote frequently observed attrs to props when reactive observation is required
20
+
21
+ ## Access Attribute and Listener Keys Correctly
22
+
23
+ Hyphenated attribute names preserve their original casing in JavaScript, so dot notation does not work for keys that include `-`.
24
+
25
+ **BAD:**
26
+
27
+ ```vue
28
+ <script setup>
29
+ import { useAttrs } from 'vue'
30
+
31
+ const attrs = useAttrs()
32
+
33
+ console.log(attrs.data - testid) // Syntax error
34
+ console.log(attrs.dataTestid) // undefined for data-testid
35
+ console.log(attrs['on-click']) // undefined
36
+ console.log(attrs['@click']) // undefined
37
+ </script>
38
+ ```
39
+
40
+ **GOOD:**
41
+
42
+ ```vue
43
+ <script setup>
44
+ import { useAttrs } from 'vue'
45
+
46
+ const attrs = useAttrs()
47
+
48
+ console.log(attrs['data-testid'])
49
+ console.log(attrs['aria-label'])
50
+ console.log(attrs['foo-bar'])
51
+
52
+ console.log(attrs.onClick)
53
+ console.log(attrs.onCustomEvent)
54
+ console.log(attrs.onMouseEnter)
55
+ </script>
56
+ ```
57
+
58
+ ### Naming Reference
59
+
60
+ | Parent Usage | Access in `attrs` |
61
+ | ------------------------- | ------------------------------ |
62
+ | `class="foo"` | `attrs.class` |
63
+ | `data-id="123"` | `attrs['data-id']` |
64
+ | `aria-label="..."` | `attrs['aria-label']` |
65
+ | `foo-bar="baz"` | `attrs['foo-bar']` |
66
+ | `@click="fn"` | `attrs.onClick` |
67
+ | `@custom-event="fn"` | `attrs.onCustomEvent` |
68
+ | `@update:modelValue="fn"` | `attrs['onUpdate:modelValue']` |
69
+
70
+ ## `useAttrs()` Is Not Reactive
71
+
72
+ `useAttrs()` always reflects the latest values, but it is intentionally not reactive for watcher tracking.
73
+
74
+ **BAD:**
75
+
76
+ ```vue
77
+ <script setup>
78
+ import { useAttrs, watch, watchEffect } from 'vue'
79
+
80
+ const attrs = useAttrs()
81
+
82
+ watch(
83
+ () => attrs.someAttr,
84
+ (newValue) => {
85
+ console.log('Changed:', newValue) // Never runs on attr changes
86
+ },
87
+ )
88
+
89
+ watchEffect(() => {
90
+ console.log(attrs.class) // Runs on setup, not on attr updates
91
+ })
92
+ </script>
93
+ ```
94
+
95
+ **GOOD:**
96
+
97
+ ```vue
98
+ <script setup>
99
+ import { onUpdated, useAttrs } from 'vue'
100
+
101
+ const attrs = useAttrs()
102
+
103
+ onUpdated(() => {
104
+ console.log('Latest attrs:', attrs)
105
+ })
106
+ </script>
107
+ ```
108
+
109
+ **GOOD:**
110
+
111
+ ```vue
112
+ <script setup>
113
+ import { watch } from 'vue'
114
+
115
+ const props = defineProps({
116
+ someAttr: String,
117
+ })
118
+
119
+ watch(
120
+ () => props.someAttr,
121
+ (newValue) => {
122
+ console.log('Changed:', newValue)
123
+ },
124
+ )
125
+ </script>
126
+ ```
127
+
128
+ ## Common Patterns
129
+
130
+ ### Check for optional attrs safely
131
+
132
+ ```vue
133
+ <script setup>
134
+ import { computed, useAttrs } from 'vue'
135
+
136
+ const attrs = useAttrs()
137
+
138
+ const hasTestId = computed(() => 'data-testid' in attrs)
139
+ const ariaLabel = computed(() => attrs['aria-label'] ?? 'Default label')
140
+ </script>
141
+ ```
142
+
143
+ ### Forward listeners after internal logic
144
+
145
+ ```vue
146
+ <script setup>
147
+ import { useAttrs } from 'vue'
148
+
149
+ defineOptions({ inheritAttrs: false })
150
+
151
+ const attrs = useAttrs()
152
+
153
+ function handleClick(event) {
154
+ console.log('Internal handling first')
155
+ attrs.onClick?.(event)
156
+ }
157
+ </script>
158
+
159
+ <template>
160
+ <button @click="handleClick">
161
+ <slot />
162
+ </button>
163
+ </template>
164
+ ```
165
+
166
+ ## TypeScript Notes
167
+
168
+ `useAttrs()` is typed as `Record<string, unknown>`, so cast individual keys when needed.
169
+
170
+ ```vue
171
+ <script setup lang="ts">
172
+ import { useAttrs } from 'vue'
173
+
174
+ const attrs = useAttrs()
175
+
176
+ const testId = attrs['data-testid'] as string | undefined
177
+ const onClick = attrs.onClick as ((event: MouseEvent) => void) | undefined
178
+ </script>
179
+ ```
@@ -0,0 +1,139 @@
1
+ ---
2
+ title: KeepAlive Component Best Practices
3
+ impact: HIGH
4
+ impactDescription: KeepAlive caches component instances; misuse causes stale data, memory growth, or unexpected lifecycle behavior
5
+ type: best-practice
6
+ tags: [vue3, keepalive, cache, performance, router, dynamic-components]
7
+ ---
8
+
9
+ # KeepAlive Component Best Practices
10
+
11
+ **Impact: HIGH** - `<KeepAlive>` caches component instances instead of destroying them. Use it to preserve state across switches, but manage cache size and freshness explicitly to avoid memory growth or stale UI.
12
+
13
+ ## Task List
14
+
15
+ - Use KeepAlive only where state preservation improves UX
16
+ - Set a reasonable `max` to cap cache size
17
+ - Declare component names for include/exclude matching
18
+ - Use `onActivated`/`onDeactivated` for cache-aware logic
19
+ - Decide how and when cached views refresh their data
20
+ - Avoid caching memory-heavy or security-sensitive views
21
+
22
+ ## When to Use KeepAlive
23
+
24
+ Use KeepAlive when switching between views where state should persist (tabs, multi-step forms, dashboards). Avoid it when each visit should start fresh.
25
+
26
+ **BAD:**
27
+
28
+ ```vue
29
+ <template>
30
+ <!-- State resets on every switch -->
31
+ <component :is="currentTab" />
32
+ </template>
33
+ ```
34
+
35
+ **GOOD:**
36
+
37
+ ```vue
38
+ <template>
39
+ <!-- State preserved between switches -->
40
+ <KeepAlive>
41
+ <component :is="currentTab" />
42
+ </KeepAlive>
43
+ </template>
44
+ ```
45
+
46
+ ## When NOT to Use KeepAlive
47
+
48
+ - Search or filter pages where users expect fresh results
49
+ - Memory-heavy components (maps, large tables, media players)
50
+ - Sensitive flows where data must be cleared on exit
51
+ - Components with heavy background activity you cannot pause
52
+
53
+ ## Limit and Control the Cache
54
+
55
+ Always cap cache size with `max` and restrict caching to specific components when possible.
56
+
57
+ ```vue
58
+ <template>
59
+ <KeepAlive :max="5" include="Dashboard,Settings">
60
+ <component :is="currentView" />
61
+ </KeepAlive>
62
+ </template>
63
+ ```
64
+
65
+ ## Ensure Component Names Match include/exclude
66
+
67
+ `include` and `exclude` match the component `name` option. Explicitly set names for reliable caching.
68
+
69
+ ```vue
70
+ <!-- TabA.vue -->
71
+ <script setup>
72
+ defineOptions({ name: 'TabA' })
73
+ </script>
74
+ ```
75
+
76
+ ```vue
77
+ <template>
78
+ <KeepAlive include="TabA,TabB">
79
+ <component :is="currentTab" />
80
+ </KeepAlive>
81
+ </template>
82
+ ```
83
+
84
+ ## Cache Invalidation Strategies
85
+
86
+ Vue 3 has no direct API to remove a specific cached instance. Use keys or dynamic include/exclude to force refreshes.
87
+
88
+ ```vue
89
+ <script setup>
90
+ import { reactive, ref } from 'vue'
91
+
92
+ const currentView = ref('Dashboard')
93
+ const viewKeys = reactive({ Dashboard: 0, Settings: 0 })
94
+
95
+ function invalidateCache(view) {
96
+ viewKeys[view]++
97
+ }
98
+ </script>
99
+
100
+ <template>
101
+ <KeepAlive>
102
+ <component :is="currentView" :key="`${currentView}-${viewKeys[currentView]}`" />
103
+ </KeepAlive>
104
+ </template>
105
+ ```
106
+
107
+ ## Lifecycle Hooks for Cached Components
108
+
109
+ Cached components are not destroyed on switch. Use activation hooks for refresh and cleanup.
110
+
111
+ ```vue
112
+ <script setup>
113
+ import { onActivated, onDeactivated } from 'vue'
114
+
115
+ onActivated(() => {
116
+ refreshData()
117
+ })
118
+
119
+ onDeactivated(() => {
120
+ pauseTimers()
121
+ })
122
+ </script>
123
+ ```
124
+
125
+ ## Router Caching and Freshness
126
+
127
+ Decide whether navigation should show cached state or a fresh view. A common pattern is to key by route when params change.
128
+
129
+ ```vue
130
+ <template>
131
+ <router-view v-slot="{ Component, route }">
132
+ <KeepAlive>
133
+ <component :is="Component" :key="route.fullPath" />
134
+ </KeepAlive>
135
+ </router-view>
136
+ </template>
137
+ ```
138
+
139
+ If you want cache reuse but fresh data, refresh in `onActivated` and compare query/params before fetching.
@@ -0,0 +1,226 @@
1
+ ---
2
+ title: Component Slots Best Practices
3
+ impact: MEDIUM
4
+ impactDescription: Poor slot API design causes empty DOM wrappers, weak TypeScript safety, brittle defaults, and unnecessary component overhead
5
+ type: best-practice
6
+ tags: [vue3, slots, components, typescript, composables]
7
+ ---
8
+
9
+ # Component Slots Best Practices
10
+
11
+ **Impact: MEDIUM** - Slots are a core component API surface in Vue. Structure them intentionally so templates stay predictable, typed, and performant.
12
+
13
+ ## Task List
14
+
15
+ - Use shorthand syntax for named slots (`#` instead of `v-slot:`)
16
+ - Render optional slot wrapper elements only when slot content exists (`$slots` checks)
17
+ - Type scoped slot contracts with `defineSlots` in TypeScript components
18
+ - Provide fallback content for optional slots
19
+ - Prefer composables over renderless components for pure logic reuse
20
+
21
+ ## Shorthand syntax for named slots
22
+
23
+ **BAD:**
24
+
25
+ ```vue
26
+ <MyComponent>
27
+ <template v-slot:header> ... </template>
28
+ </MyComponent>
29
+ ```
30
+
31
+ **GOOD:**
32
+
33
+ ```vue
34
+ <MyComponent>
35
+ <template #header> ... </template>
36
+ </MyComponent>
37
+ ```
38
+
39
+ ## Conditionally Render Optional Slot Wrappers
40
+
41
+ Use `$slots` checks when wrapper elements add spacing, borders, or layout constraints.
42
+
43
+ **BAD:**
44
+
45
+ ```vue
46
+ <!-- Card.vue -->
47
+ <template>
48
+ <article class="card">
49
+ <header class="card-header">
50
+ <slot name="header" />
51
+ </header>
52
+
53
+ <section class="card-body">
54
+ <slot />
55
+ </section>
56
+
57
+ <footer class="card-footer">
58
+ <slot name="footer" />
59
+ </footer>
60
+ </article>
61
+ </template>
62
+ ```
63
+
64
+ **GOOD:**
65
+
66
+ ```vue
67
+ <!-- Card.vue -->
68
+ <template>
69
+ <article class="card">
70
+ <header v-if="$slots.header" class="card-header">
71
+ <slot name="header" />
72
+ </header>
73
+
74
+ <section v-if="$slots.default" class="card-body">
75
+ <slot />
76
+ </section>
77
+
78
+ <footer v-if="$slots.footer" class="card-footer">
79
+ <slot name="footer" />
80
+ </footer>
81
+ </article>
82
+ </template>
83
+ ```
84
+
85
+ ## Type Scoped Slot Props with defineSlots
86
+
87
+ In `<script setup lang="ts">`, use `defineSlots` so slot consumers get autocomplete and static checks.
88
+
89
+ **BAD:**
90
+
91
+ ```vue
92
+ <!-- ProductList.vue -->
93
+ <script setup lang="ts">
94
+ interface Product {
95
+ id: number
96
+ name: string
97
+ }
98
+
99
+ defineProps<{ products: Product[] }>()
100
+ </script>
101
+
102
+ <template>
103
+ <ul>
104
+ <li v-for="(product, index) in products" :key="product.id">
105
+ <slot :product="product" :index="index" />
106
+ </li>
107
+ </ul>
108
+ </template>
109
+ ```
110
+
111
+ **GOOD:**
112
+
113
+ ```vue
114
+ <!-- ProductList.vue -->
115
+ <script setup lang="ts">
116
+ interface Product {
117
+ id: number
118
+ name: string
119
+ }
120
+
121
+ defineProps<{ products: Product[] }>()
122
+
123
+ defineSlots<{
124
+ default: (props: { product: Product; index: number }) => any
125
+ empty: () => any
126
+ }>()
127
+ </script>
128
+
129
+ <template>
130
+ <ul v-if="products.length">
131
+ <li v-for="(product, index) in products" :key="product.id">
132
+ <slot :product="product" :index="index" />
133
+ </li>
134
+ </ul>
135
+ <slot v-else name="empty" />
136
+ </template>
137
+ ```
138
+
139
+ ## Provide Slot Fallback Content
140
+
141
+ Fallback content makes components resilient when parents omit optional slots.
142
+
143
+ **BAD:**
144
+
145
+ ```vue
146
+ <!-- SubmitButton.vue -->
147
+ <template>
148
+ <button type="submit" class="btn-primary">
149
+ <slot />
150
+ </button>
151
+ </template>
152
+ ```
153
+
154
+ **GOOD:**
155
+
156
+ ```vue
157
+ <!-- SubmitButton.vue -->
158
+ <template>
159
+ <button type="submit" class="btn-primary">
160
+ <slot>Submit</slot>
161
+ </button>
162
+ </template>
163
+ ```
164
+
165
+ ## Prefer Composables for Pure Logic Reuse
166
+
167
+ Renderless components are still useful for slot-driven composition, but composables are usually cleaner for logic-only reuse.
168
+
169
+ **BAD:**
170
+
171
+ ```vue
172
+ <!-- MouseTracker.vue -->
173
+ <script setup lang="ts">
174
+ import { onMounted, onUnmounted, ref } from 'vue'
175
+
176
+ const x = ref(0)
177
+ const y = ref(0)
178
+
179
+ function onMove(event: MouseEvent) {
180
+ x.value = event.pageX
181
+ y.value = event.pageY
182
+ }
183
+
184
+ onMounted(() => window.addEventListener('mousemove', onMove))
185
+ onUnmounted(() => window.removeEventListener('mousemove', onMove))
186
+ </script>
187
+
188
+ <template>
189
+ <slot :x="x" :y="y" />
190
+ </template>
191
+ ```
192
+
193
+ **GOOD:**
194
+
195
+ ```ts
196
+ // composables/useMouse.ts
197
+ import { onMounted, onUnmounted, ref } from 'vue'
198
+
199
+ export function useMouse() {
200
+ const x = ref(0)
201
+ const y = ref(0)
202
+
203
+ function onMove(event: MouseEvent) {
204
+ x.value = event.pageX
205
+ y.value = event.pageY
206
+ }
207
+
208
+ onMounted(() => window.addEventListener('mousemove', onMove))
209
+ onUnmounted(() => window.removeEventListener('mousemove', onMove))
210
+
211
+ return { x, y }
212
+ }
213
+ ```
214
+
215
+ ```vue
216
+ <!-- MousePosition.vue -->
217
+ <script setup lang="ts">
218
+ import { useMouse } from '@/composables/useMouse'
219
+
220
+ const { x, y } = useMouse()
221
+ </script>
222
+
223
+ <template>
224
+ <p>{{ x }}, {{ y }}</p>
225
+ </template>
226
+ ```