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
It's common for an app to be organized into a tree of nested components:
74
+
一般的にアプリケーションはネストされたコンポーネントのツリーに編成されます:
75
75
76
-

76
+

77
77
78
-
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:
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.
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).
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:
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`.
In a typical app, however, you'll likely have an array of posts in `data`:
130
+
しかしながら、一般的なアプリケーションではおそらく `data` に投稿の配列を持っています:
131
131
132
132
```js
133
133
constApp= {
@@ -136,23 +136,23 @@ const App = {
136
136
posts: [
137
137
{ id:1, title:'My journey with Vue' },
138
138
{ id:2, title:'Blogging with Vue' },
139
-
{ id:3, title:'Why Vue is so fun' },
140
-
],
139
+
{ id:3, title:'Why Vue is so fun' }
140
+
]
141
141
}
142
-
},
142
+
}
143
143
}
144
144
145
145
constapp=Vue.createApp(App)
146
146
147
147
app.component('blog-post', {
148
148
props: ['title'],
149
-
template:`<h4>{{ title }}</h4>`,
149
+
template:`<h4>{{ title }}</h4>`
150
150
})
151
151
152
152
app.mount('#blog-posts-demo')
153
153
```
154
154
155
-
Then want to render a component for each one:
155
+
そしてコンポーネントをそれぞれ描画します:
156
156
157
157
```html
158
158
<divid="blog-posts-demo">
@@ -164,9 +164,9 @@ Then want to render a component for each one:
164
164
</div>
165
165
```
166
166
167
-
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](component-props.html).
0 commit comments