# Components Basics {#components-basics} Components allow us to split the UI into independent and reusable pieces, and think about each piece in isolation. It's common for an app to be organized into a tree of nested components: ![Component Tree](./images/components.png) This is very similar to how we nest native HTML elements, but Vue implements its own component model that allows us to encapsulate custom content and logic in each component. Vue also plays nicely with native Web Components. If you are curious about the relationship between Vue Components and native Web Components, [read more here](/guide/extras/web-components). ## Defining a Component {#defining-a-component} When using a build step, we typically define each Vue component in a dedicated file using the `.vue` extension - known as a [Single-File Component](/guide/scaling-up/sfc) (SFC for short):
```vue ```
```vue ```
When not using a build step, a Vue component can be defined as a plain JavaScript object containing Vue-specific options:
```js export default { data() { return { count: 0 } }, template: ` ` } ```
```js import { ref } from 'vue' export default { setup() { const count = ref(0) return { count } }, template: ` ` // Can also target an in-DOM template: // template: '#my-template-element' } ```
The template is inlined as a JavaScript string here, which Vue will compile on the fly. You can also use an ID selector pointing to an element (usually native `