prop父子组件通信,动静态prop

215 阅读1分钟

子组件: Vue.component('blog-post', { // 在 JavaScript 中是 camelCase 的 props: ['postTitle'], template: '

{{ postTitle }}

' }) 父组件中使用子组件: 可以有多个prop, props: ['title', 'likes', 'isPublished', 'commentIds', 'author'] 然后每个prop可以指定类型 props: { title: String, likes: Number, isPublished: Boolean, commentIds: Array, author: Object } 传递静态值 传递动态值:

还有一点 post: { id: 1, title: 'My Journey with Vue' } 下面的模板:

等价于:

<blog-post v-bind:id="post.id" v-bind:title="post.title"