父子组件传值
1.父传子
父组件vue中,对子组件设定属性
<HelloWorld :msg="msg" />
子组件中可接受属性达成传值,props中的属性类似data
props: {
msg: {
type: String,//类型
required: true, //必填
default: “123”, //默认值
validator:(value)=> xx //校验项
}
},
2.子传父
在父组件vue中,给子组件绑定事件
<child @parent=“parentDo”/>
在父组件中编写事件,获得值
parentDo(value){
value;
}
在子组件中可以触发该事件,发送值
this.$emit(“parentDo”,value)
3.父拿子
在父组件vue中,子组件上设定ref属性
<child ref=“childName”>
父组件可直接拿到
this.$refs.childName
4.父子互拿
this.$children / this.$parent