prop父子元件通訊,動靜態prop

MayDo發表於2018-10-17

子元件: 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"

相關文章