16 rules of VueJS 2 for an AI Agent to follow.
Document Code Thoroughly:
Use key Attribute in v-for:
Always include a unique key attribute when using v-for to help Vue efficiently track and update DOM elements.
Kebab-Case for Event Names:
Use kebab-case for event names (e.g., user-clicked) to follow Vue.js conventions.
Return Function from data Option:
Ensure the data option always returns a function to prevent shared state across component instances.
Avoid Combining v-if and v-for:
Do not use v-if and v-for on the same element. Instead, filter data using computed properties or methods.
PascalCase for Component Files:
Name component files using PascalCase (e.g., UserProfile.vue) and use kebab-case when referring to them in templates.
Scoped Styles:
Use `` to prevent CSS conflicts between components.
Reusable Components:
Break down UI elements into reusable, focused components to improve maintainability and scalability.
Clean Templates:
Avoid complex logic in templates; instead, use computed properties or methods to simplify template code.
Prop Validation:
Define props with proper types, default values, and validation rules using the props option.
Base Component Naming:
Prefix base components (e.g., BaseButton, BaseInput) for easy identification across the project.
Linting and Formatting:
Implement ESLint with Vue-specific configurations and Prettier for consistent code formatting across the project.
Document Props and Events:
Component-Level Documentation:
Begin each component file with a comment block describing:
Readable Code Structure:
Organize code logically with clear separation between template, script, and style sections in .vue files.