mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-10 01:50:08 +00:00
Amp-Thread-ID: https://ampcode.com/threads/T-019bdfa7-58b4-731b-83ee-83f2b2bea030 Co-authored-by: Amp <amp@ampcode.com>
2.1 KiB
2.1 KiB
globs
| globs | |
|---|---|
|
Vue Component Conventions
Applies to all .vue files anywhere in the codebase.
Vue 3 Composition API
-
Use
<script setup lang="ts">for component logic -
Destructure props (Vue 3.5 style with defaults):
const { nodes, showTotal = true } = defineProps<{ nodes: ApiNodeCost[] showTotal?: boolean }>() -
Do not use
withDefaultsor runtime props declaration -
Do not import Vue macros unnecessarily
-
Prefer
defineModelover separate prop/emit for v-model bindings -
Define slots via template usage, not
defineSlots -
Use same-name shorthand for slot props:
:is-expandednot:is-expanded="isExpanded" -
Derive component types using
vue-component-type-helpers(ComponentProps,ComponentSlots)
State Management
- Use
ref/reactivefor state,computed()for derived state - Use lifecycle hooks:
onMounted,onUpdated, etc. - Prefer
computedoverwatchwhen possible - Prefer
watch/watchEffectonly for side effects - Be judicious with refs — if a prop suffices, don't add a ref
- Use provide/inject only when a Store or shared composable won't work
Component Communication
- Prefer
emit/@event-namefor state changes (promotes loose coupling) - Use
defineExposeonly for imperative operations (form.validate(),modal.open()) - Proper props and emits definitions
VueUse Composables
Prefer VueUse composables over manual event handling:
useElementHoverinstead of manual mouseover/mouseout listenersuseIntersectionObserverfor visibility detection instead of scroll handlersuseFocusTrapfor modal/dialog focus managementuseEventListenerfor auto-cleanup event listeners
Prefer Vue native options when available:
defineModelinstead ofuseVModelfor two-way binding with props
Styling
- Use inline Tailwind CSS only (no
<style>blocks) - Use
cn()from@/utils/tailwindUtilfor conditional classes - Refer to packages/design-system/src/css/style.css for design tokens and tailwind configuration
Best Practices
- Extract complex conditionals to
computed - In unmounted hooks, implement cleanup for async operations