通过 Prop 向子组件传递数据

prop 是你可以在组件上注册的一些自定义特性。

当一个值传递给一个prop特性的时候,他就变成了那个

组件实例的一个属性。

为了给博文组件传递一个标题,我们可以用一个 props 选项

将其包含在该组件可接受的prop列表中:

注册:Vue.component('blog-post', { props: ['title'], template: '<h3>{{ title }}</h3>' })

 

使用:<blog-post title="My journey with Vue"></blog-post> <blog-post title="Blogging with Vue"></blog-post> <blog-post title="Why Vue is so fun"></blog-post>

 

使用条件:new Vue({ el: '#blog-post-demo', data: { posts: [ { id: 1, title: 'My journey with Vue' }, { id: 2, title: 'Blogging with Vue' }, { id: 3, title: 'Why Vue is so fun' } ] } })

 

接口使用:<blog-post v-for="post in posts" v-bind:key="post.id" v-bind:title="post.title" ></blog-post>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值