diff --git a/src/guide/component-basics.md b/src/guide/component-basics.md index 366d939b12..6f17729235 100644 --- a/src/guide/component-basics.md +++ b/src/guide/component-basics.md @@ -40,7 +40,7 @@ app.mount('#components-demo') -Since components are reusable 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`. +Since components are reusable instances, they accept the same options as a root instance, such as `data`, `computed`, `watch`, `methods`, and lifecycle hooks. ## Reusing Components @@ -66,7 +66,7 @@ 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: +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 the `component` method of our app: ```js const app = Vue.createApp({}) @@ -76,7 +76,7 @@ app.component('my-component-name', { }) ``` -Globally registered components can be used in the template of `app` instance created afterwards - and even inside all subcomponents of that root instance's component tree. +Globally registered components can be used in the template of any component within the app. 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](component-registration.md). @@ -84,7 +84,7 @@ That's all you need to know about registration for now, but once you've finished 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: +Props are custom attributes you can register on a component. To pass a title to our blog post component, we can include it in the list of props this component accepts, using the `props` option: ```js const app = Vue.createApp({}) @@ -97,7 +97,9 @@ app.component('blog-post', { app.mount('#blog-post-demo') ``` -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`. +When a value is passed to a prop attribute, it becomes a property on that component instance. The value of that property is accessible within the template, just like any other component property. + +A component can have as many props as you like and, by default, any value can be passed to any prop. Once a prop is registered, you can pass data to it as a custom attribute, like this: @@ -175,7 +177,7 @@ Which can be used in the template to control the font size of all blog posts: ```html
-
+
@@ -205,7 +207,7 @@ The problem is, this button doesn't do anything: ``` -When we click on the button, we need to communicate to the parent that it should enlarge the text of all posts. Fortunately, component 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` or `@`, just as we would with a native DOM event: +When we click on the button, we need to communicate to the parent that it should enlarge the text of all posts. To solve this problem, component instances provide a custom events system. The parent can choose to listen to any event on the child component instance with `v-on` or `@`, just as we would with a native DOM event: ```html @@ -219,11 +221,11 @@ Then the child component can emit an event on itself by calling the built-in [** ``` -Thanks to the `@enlarge-text="postFontSize += 0.1"` listener, the parent will receive the event and update `postFontSize` value. +Thanks to the `@enlarge-text="postFontSize += 0.1"` listener, the parent will receive the event and update the value of `postFontSize`. -We can list emitted events in the component's `emits` option. +We can list emitted events in the component's `emits` option: ```js app.component('blog-post', { @@ -232,11 +234,11 @@ app.component('blog-post', { }) ``` -This will allow you to check all the events component emits and optionally [validate them](component-custom-events.html#validate-emitted-events) +This will allow you to check all the events that a component emits and optionally [validate them](component-custom-events.html#validate-emitted-events). ### 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: +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 pass a second parameter to `$emit` to provide this value: ```html