Skip to content

Commit b07e74f

Browse files
committed
🚧 VueJS naming convention in progress
1 parent c70ac03 commit b07e74f

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

vuejs/components-naming.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# VueJS Naming Convention > Components Naming
1+
# VueJS Naming Convention > Components Naming
2+
3+
## PascalCase
4+
- Begin with an uppercase letter
5+
- Components names should always be multiwords like "AlertModal", "DropdownMenu" or "NavbarLogo"
6+
- Child components should use the name of their parent as a preffix. For example a Form component child of AlertModal should be called AlertModalForm
7+
- Avoid acronyms and abbreviations
8+
9+
10+
```javascript
11+
export default {
12+
name: 'AlertModal'
13+
}
14+
```
15+

vuejs/smart-dumb-naming.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
# VueJS Naming Convention > Smart vs Dumb Components Naming
1+
# VueJS Naming Convention > Smart vs Dumb Components Naming
2+
3+
Smart components sometimes called contrainer are the one that handles state changes. Dumb components, also called presentational, handles the look and feel. Dumb components are comparable to the View and Smart component to the Controller in the MVC pattern.
4+
5+
## Dumb components
6+
- Starts with the prefix "Base", "App" or "V"
7+
- For example "BaseButton", "AppButton" or "VButton" for a simple button
8+
- Takes only care of the look and feel
9+
10+
## Smart components
11+
- Takes the name of a dumb component but replace the prefix ("Base", "App" or "V") with another name
12+
- For example "SubmitButton", "UserDeleteButton", "IncrementButton"
13+
- Implements methods or are connected with the Vuex actions
14+
15+
```javascript
16+
<template>
17+
<div class="increment-button" v-on:click="increment">
18+
<base-button>{{ number }} Increment</base-button>
19+
</div>
20+
</template>
21+
22+
<script>
23+
// Base Button is dumb
24+
const BaseButton = {
25+
template: `<button><slot></slot></button>`
26+
}
27+
28+
// Increment Button is smart
29+
export default {
30+
name: 'IncrementButton',
31+
components: { BaseButton },
32+
data () {
33+
return {
34+
number: 0
35+
}
36+
},
37+
methods: {
38+
increment () {
39+
this.number++
40+
}
41+
}
42+
}
43+
</script>
44+
```

0 commit comments

Comments
 (0)