props父组件传值 子组件接收
- 小菜鸟
> 父组件传入值
> // 用 v-bond="post" 传入
<getcode v-bind="post" ></getcode>
retutn{
post: {
background:'#fff',
width:296,
height:231
},
}
子组件接收 检测类型 type: Number, 传过来的值与接收的值类型不一样,会报错,
props: {
width:{
type: Number,
default:296,
},
height:{
type:Number,
default:231,
},
background:{
type:String,
default:'#fff'
},
},
> 在子组件里div里面使用传过来的值
<div class="background"
:style="{width:width +'px', height:height+'px',background:background}"
>
</div>