Kuru
Kuru

Reputation: 1517

Should a component have its parent's file name as part of its own file name?

I want to ask the correct way to name a component file.

I read the style guide.

https://v2.vuejs.org/v2/style-guide/

I am wondering, if you make a directory contain some child components of specific component, should those child component names start with the parent component's name?

// OPTION 1:

file) ParentA.vue

directory) ParentA

 |_ file) ParentAChildA.vue
// OPTION 2

file) ParentA.vue

directory) ParentA

 |_ file) ChildA.vue

Which is proper?

Upvotes: 0

Views: 157

Answers (1)

sandrooco
sandrooco

Reputation: 8716

I think this is kind of opinion based. Most developers use both approaches. Why?

Example for option 1: Imagine a todo list from a classic todo app. First we have TodoList as wrapper for the items, maybe with some sorting options and so on. One item (= child component) would then be called TodoListItem.

Example for option 2: Imagine some dashboard-style app. We have multiple shown components that aren't directly mutual (can but don't have to be). So we would have a Dashboard component. Of course, DashboardItem with dynamic values would also work but is overkill for most applications. So one would just use Dashboard and then Investments as child.

Most important: Be concise and consistent in naming your components (and of course also variables, services, etc.).

Upvotes: 1

Related Questions