You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/introduction.md
+17-20Lines changed: 17 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -211,18 +211,16 @@ The component system is another important concept in Vue, because it's an abstra
211
211
In Vue, a component is essentially a Vue 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:
212
212
213
213
```js
214
-
// Define a new component called todo-item
215
-
constTodoItem= {
216
-
template:'<li>This is a todo</li>'
217
-
}
214
+
// Create Vue application
215
+
constapp=Vue.createApp()
218
216
219
-
constApp= {
220
-
components: {
221
-
'todo-item': TodoItem
222
-
}
223
-
}
217
+
// Define a new component called todo-item
218
+
app.component('todo-item', {
219
+
template:`<li>This is a todo</li>`
220
+
})
224
221
225
-
Vue.createApp().mount(...)
222
+
// Mount Vue application
223
+
app.mount(...)
226
224
```
227
225
228
226
Now you can compose it in another component's template:
@@ -237,10 +235,10 @@ Now you can compose it in another component's template:
237
235
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](TODO:components.html#Props):
238
236
239
237
```js
240
-
constTodoItem= {
238
+
app.component('todo-item', {
241
239
props: ['todo'],
242
-
template:'<li>{{ todo.text }}</li>'
243
-
}
240
+
template:`<li>{{ todo.text }}</li>`
241
+
})
244
242
```
245
243
246
244
Now we can pass the todo into each repeated component using `v-bind`:
@@ -264,10 +262,12 @@ Now we can pass the todo into each repeated component using `v-bind`:
264
262
```
265
263
266
264
```js
267
-
constTodoItem= {
265
+
constapp=Vue.createApp()
266
+
267
+
app.component('todo-item', {
268
268
props: ['todo'],
269
-
template:'<li>{{ todo.text }}</li>'
270
-
}
269
+
template:`<li>{{ todo.text }}</li>`
270
+
})
271
271
272
272
constApp7= {
273
273
data() {
@@ -278,13 +278,10 @@ const App7 = {
278
278
{ id:2, text:'Whatever else humans are supposed to eat' }
0 commit comments