+
+## Base Example
+
+Here's an example of a Vue component:
+
+```js
+// Create a Vue application
+const app = Vue.createApp({})
+
+// Define a new global component called button-counter
+app.component('button-counter', {
+ data() {
+ return {
+ count: 0
+ }
+ },
+ template: ``
+})
+```
+
+Components are reusable Vue instances with a name: in this case, ``. We can use this component as a custom element inside a root Vue instance:
+
+```html
+
+
+
+```
+
+```js
+app.mount('#components-demo')
+```
+
+
+
+Since components are reusable Vue instances, they accept the same options as a root instance, such as `data`, `computed`, `watch`, `methods`, and lifecycle hooks. The only exceptions are a few root-specific options like `el`.
+
+## Reusing Components
+
+Components can be reused as many times as you want:
+
+```html
+
+
+
+
+
+```
+
+
+
+Notice that when clicking on the buttons, each one maintains its own, separate `count`. That's because each time you use a component, a new **instance** of it is created.
+
+## Organizing Components
+
+It's common for an app to be organized into a tree of nested components:
+
+
+
+For example, you might have components for a header, sidebar, and content area, each typically containing other components for navigation links, blog posts, etc.
+
+To use these components in templates, they must be registered so that Vue knows about them. There are two types of component registration: **global** and **local**. So far, we've only registered components globally, using `component` method of created app:
+
+```js
+const app = Vue.createApp()
+
+app.component('my-component-name', {
+ // ... options ...
+})
+```
+
+Globally registered components can be used in the template of `app` instance created afterwards - and even inside all subcomponents of that Vue instance's component tree.
+
+That's all you need to know about registration for now, but once you've finished reading this page and feel comfortable with its content, we recommend coming back later to read the full guide on [Component Registration](TODO:components-registration.html).
+
+## Passing Data to Child Components with Props
+
+Earlier, we mentioned creating a component for blog posts. The problem is, that component won't be useful unless you can pass data to it, such as the title and content of the specific post we want to display. That's where props come in.
+
+Props are custom attributes you can register on a component. When a value is passed to a prop attribute, it becomes a property on that component instance. To pass a title to our blog post component, we can include it in the list of props this component accepts, using a `props` option:
+
+```js
+const app = Vue.createApp()
+
+app.component('blog-post', {
+ props: ['title'],
+ template: `
{{ title }}
`
+})
+```
+
+A component can have as many props as you'd like and by default, any value can be passed to any prop. In the template above, you'll see that we can access this value on the component instance, just like with `data`.
+
+Once a prop is registered, you can pass data to it as a custom attribute, like this:
+
+```html
+
+
+
+```
+
+
+
+In a typical app, however, you'll likely have an array of posts in `data`:
+
+```js
+const App = {
+ data() {
+ return {
+ posts: [
+ { id: 1, title: 'My journey with Vue' },
+ { id: 2, title: 'Blogging with Vue' },
+ { id: 3, title: 'Why Vue is so fun' }
+ ]
+ }
+ }
+}
+
+const app = Vue.createApp()
+
+app.component('blog-post', {
+ props: ['title'],
+ template: `
{{ title }}
`
+})
+
+app.mount('#blog-posts-demo')
+```
+
+Then want to render a component for each one:
+
+```html
+
+
+
+```
+
+Above, you'll see that we can use `v-bind` to dynamically pass props. This is especially useful when you don't know the exact content you're going to render ahead of time.
+
+That's all you need to know about props for now, but once you've finished reading this page and feel comfortable with its content, we recommend coming back later to read the full guide on [Props](TODO:components-props.html).
+
+## Listening to Child Components Events
+
+As we develop our `` component, some features may require communicating back up to the parent. For example, we may decide to include an accessibility feature to enlarge the text of blog posts, while leaving the rest of the page its default size.
+
+In the parent, we can support this feature by adding a `postFontSize` data property:
+
+```js
+const App = {
+ data() {
+ return {
+ posts: [
+ /* ... */
+ ],
+ postFontSize: 1
+ }
+ }
+}
+```
+
+Which can be used in the template to control the font size of all blog posts:
+
+```html
+
+
+
+
+
+```
+
+Now let's add a button to enlarge the text right before the content of every post:
+
+```js
+app.component('blog-post', {
+ props: ['title'],
+ template: `
+
+
{{ title }}
+
+
+ `
+})
+```
+
+The problem is, this button doesn't do anything:
+
+```html
+
+```
+
+When we click on the button, we need to communicate to the parent that it should enlarge the text of all posts. Fortunately, Vue instances provide a custom events system to solve this problem. The parent can choose to listen to any event on the child component instance with `v-on`, just as we would with a native DOM event:
+
+```html
+
+```
+
+Then the child component can emit an event on itself by calling the built-in [**`$emit`** method](TODO:../api/#vm-emit), passing the name of the event:
+
+```html
+
+```
+
+Thanks to the `v-on:enlarge-text="postFontSize += 0.1"` listener, the parent will receive the event and update `postFontSize` value.
+
+
+
+### Emitting a Value With an Event
+
+It's sometimes useful to emit a specific value with an event. For example, we may want the `` component to be in charge of how much to enlarge the text by. In those cases, we can use `$emit`'s 2nd parameter to provide this value:
+
+```html
+
+```
+
+Then when we listen to the event in the parent, we can access the emitted event's value with `$event`:
+
+```html
+
+```
+
+Or, if the event handler is a method:
+
+```html
+
+```
+
+Then the value will be passed as the first parameter of that method:
+
+```js
+methods: {
+ onEnlargeText(enlargeAmount) {
+ this.postFontSize += enlargeAmount
+ }
+}
+```
+
+### Using `v-model` on Components
+
+Custom events can also be used to create custom inputs that work with `v-model`. Remember that:
+
+```html
+
+```
+
+does the same thing as:
+
+```html
+
+```
+
+When used on a component, `v-model` instead does this:
+
+```html
+
+```
+
+::: warning
+Please note we used `model-value` with kebab-case here because we are working with in-DOM template. You can find a detailed explanation on kebab-cased vs camelCased attributes in the [DOM Template Parsing Caveats](#dom-template-parsing-caveats) section
+:::
+
+For this to actually work though, the `` inside the component must:
+
+- Bind the `value` attribute to a `modelValue` prop
+- On `input`, emit an `update:modelValue` event with the new value
+
+Here's that in action:
+
+```js
+app.component('custom-input', {
+ props: ['modelValue'],
+ template: `
+
+ `
+})
+```
+
+Now `v-model` should work perfectly with this component:
+
+```html
+
+```
+
+That's all you need to know about custom component events for now, but once you've finished reading this page and feel comfortable with its content, we recommend coming back later to read the full guide on [Custom Events](TODO:components-custom-events.html).
+
+## Content Distribution with Slots
+
+Just like with HTML elements, it's often useful to be able to pass content to a component, like this:
+
+```html
+
+ Something bad happened.
+
+```
+
+Which might render something like:
+
+
+
+Fortunately, this task is made very simple by Vue's custom `` element:
+
+```js
+app.component('alert-box', {
+ template: `
+
+ Error!
+
+
+ `
+})
+```
+
+As you'll see above, we just add the slot where we want it to go -- and that's it. We're done!
+
+That's all you need to know about slots for now, but once you've finished reading this page and feel comfortable with its content, we recommend coming back later to read the full guide on [Slots](TODO:components-slots.html).
+
+## Dynamic Components
+
+Sometimes, it's useful to dynamically switch between components, like in a tabbed interface:
+
+
+
+The above is made possible by Vue's `` element with the `is` special attribute:
+
+```html
+
+
+```
+
+In the example above, `currentTabComponent` can contain either:
+
+- the name of a registered component, or
+- a component's options object
+
+See [this sandbox](https://codesandbox.io/s/dynamic-components-dvtl8) to experiment with the full code, or [this version](https://codesandbox.io/s/dynamic-components-with-options-xfnrp) for an example binding to a component's options object, instead of its registered name.
+
+Keep in mind that this attribute can be used with regular HTML elements, however they will be treated as components, which means all attributes **will be bound as DOM attributes**. For some properties such as `value` to work as you would expect, you will need to bind them using the [`.prop` modifier](TODO:../api/#v-bind).
+
+That's all you need to know about dynamic components for now, but once you've finished reading this page and feel comfortable with its content, we recommend coming back later to read the full guide on [Dynamic & Async Components](TODO:components-dynamic-async.html).
+
+## DOM Template Parsing Caveats
+
+Some HTML elements, such as `