Skip to content

Fix grammatical errors and introduce app.component() in introduction.md #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/guide/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Counter = {
Vue.createApp(Counter).mount('#counter')
```

We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Take a look at the example below where `counter` property increments every second and you will see how rendered DOM changes:
We have already created our very first Vue app! This looks pretty similar to rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Take a look at the example below where the `counter` property increments every second and you will see how the rendered DOM changes:

```js{8-10}
const Counter = {
Expand Down Expand Up @@ -158,7 +158,7 @@ Vue.createApp(TwoWayBinding).mount('#two-way-binding')

## Conditionals and Loops

It's easy to toggle the presence of an element, too:
It's easy to toggle the presence of an element too:

```html
<div id="conditional-rendering">
Expand Down Expand Up @@ -220,7 +220,7 @@ The component system is another important concept in Vue, because it's an abstra

![Component Tree](/images/components.png)

In Vue, a component is essentially an instance with pre-defined options. Registering a component in Vue is straightforward: we create a component object as we did with `App` objects and we define it in parent's `components` option:
In Vue, a component is essentially an instance with pre-defined options. Registering a component in Vue is straightforward: we create a component object as we did with the `app` object and we define it in the parent's `components` option:

```js
const TodoItem = {
Expand Down Expand Up @@ -251,10 +251,10 @@ Now you can compose it in another component's template:
But this would render the same text for every todo, which is not super interesting. We should be able to pass data from the parent scope into child components. Let's modify the component definition to make it accept a [prop](component-basics.html#passing-data-to-child-components-with-props):

```js
app.component('todo-item', {
const TodoItem = {
props: ['todo'],
template: `<li>{{ todo.text }}</li>`
})
}
```

Now we can pass the todo into each repeated component using `v-bind`:
Expand All @@ -278,6 +278,11 @@ Now we can pass the todo into each repeated component using `v-bind`:
```

```js
const TodoItem = {
props: ['todo'],
template: `<li>{{ todo.text }}</li>`
}

const TodoList = {
data() {
return {
Expand All @@ -287,22 +292,20 @@ const TodoList = {
{ id: 2, text: 'Whatever else humans are supposed to eat' }
]
}
},
components: {
TodoItem
}
}

const app = Vue.createApp(TodoList)

app.component('todo-item', {
props: ['todo'],
template: `<li>{{ todo.text }}</li>`
})

app.mount('#todo-list-app')
```

<common-codepen-snippet title="Intro-Components-1" slug="VwLxeEz" />

This is a contrived example, but we have managed to separate our app into two smaller units, and the child is reasonably well-decoupled from the parent via the props interface. We can now further improve our `<todo-item>` component with more complex template and logic without affecting the parent app.
This is a contrived example, but we have managed to separate our app into two smaller units, and the child is reasonably well-decoupled from the parent via the props interface. We can now further improve our `<todo-item>` component with a more complex template and logic without affecting the parent app.

In a large application, it is necessary to divide the whole app into components to make development manageable. We will talk a lot more about components [later in the guide](component-basics.html), but here's an (imaginary) example of what an app's template might look like with components:

Expand Down