- This is a guide to be used with Vue
- Idealized to be used with Nuxt2, but can be used with others versions as well
- Names must use camelCase
buttonColor
instead of anything else
- Names must have no more than 3 words
crypoSelected
instead oftheLastCryptoThatTheUserSelected
- Vue accept kebab-case when passing props, but all props should de camelCase
<component userName="" />
instead of<component user-name="" />
- Components must start with a capital letter
MyComponent
instead ofmy-component
ormyComponent
- Components must have at least two words
MainHeader
instead ofHeader
- It should start with the context
ClearSearchButton
instead ofButtonToClearSearch
- If the component is a modal it must end with "Modal"
MyComponentModal
instead ofmy-component-modal
orMyComponent
- The name of the util file must explain what kind of util functions the file have
errors.js
instead ofutils.js
- Don't know how to create a util file/function? Read this and learn by yourself
- Componentes that are not a page must be in the components folder
- The component folder must be divided in what type that component is
- For example, modals must be on
/components/modals
- They should have just one use, no more, no less.
- A button will always be a button. A successModal will always be just a successModal
- Ps.: Don't fear in create a component that just wrapp two or three other components, changing just the props.
- When your page have too much code and you want to split it
- When you are repeating a lot of code
- First
template
thenscript
and end withstyle
- NEVER use logic on the template, instead, use a computed, a function, a watch, a ref, anything but to put the logic on template
- ALWAYS use
scoped
on your style, and if you need to style a extern component, put everything inside a container with an id and use this id in the styles, so the css won't change anything besides this component:<template> <div id="uniqueContainerID">{{ content }}</div>
<style lang="scss"> #uniqueContainerID { everyRuleInsideThisSelector } </style>
- Always use shorthands!
:src="imageSrc"
instead ofv-bind:src="imageSrc"
@click="clickHandler"
instead ofv-on:click="clickHandler"
- NEVER just declare props
- ALWAYS give context, at least, their type
props: { title: String }
orinstead ofprops:{ title: { type: String, required: true } }
props: ['title']
- Your component is independent
- Your component use the data from the store, but the parent doesn't
- Pages, as they don't have props
- Your component have a parent that use the same data
- So you will import the store in the parent and pass just the data the child component needs via props