---
name: sdlc-vue-conventions
description: |
Vue 3 SFC structure, Composition API +
```
Section order is convention; pick per project. `
```
Parent:
```vue
```
For Vue 3.3 and earlier, use the manual props+emits pattern.
## Composables
```ts
// src/composables/useDebounce.ts
import { ref, watch, onBeforeUnmount } from 'vue';
import type { Ref } from 'vue';
export function useDebounce(value: Ref, delay = 300): Ref {
const debounced = ref(value.value) as Ref;
let timer: ReturnType | undefined;
watch(value, (newVal) => {
if (timer) clearTimeout(timer);
timer = setTimeout(() => { debounced.value = newVal; }, delay);
});
onBeforeUnmount(() => { if (timer) clearTimeout(timer); });
return debounced;
}
```
Conventions:
- Name `useFooBar()`.
- Take refs as input, return refs as output.
- Cleanup side effects in `onBeforeUnmount`.
- Pure composables (no DOM access) → easy to test.
VueUse (`@vueuse/core`) provides 200+ pre-built composables — check before writing your own.
## Lifecycle hooks
```ts
import { onMounted, onBeforeMount, onUpdated, onBeforeUnmount, onUnmounted, onErrorCaptured, onActivated, onDeactivated } from 'vue';
onMounted(() => { /* DOM ready */ });
onBeforeUnmount(() => { /* cleanup */ });
onErrorCaptured((err, instance, info) => { /* error boundary */ return false; });
```
`onActivated` / `onDeactivated` fire when wrapped in ``.
In `
```
Differences from Vue 3:
- No `