VUE组件通信(子传父)

Vue组件通信子组件传值给父组件主要通过$emit

给子组件绑定一个事件

//子组件 @事件名=‘函数’
<child @children='fn'></child>
//在子组件methods选项卡中添加事件
methods:{
  fn(){
  //this.$emit('父组件绑定事件名',值) this.$emit(‘father’,value) } }

在父组件中给子组件标签绑定事件

<father>
   <!--> <child @事件名=‘函数’ </--> <child @father='father'></child> <father> //父组件methods选项卡中用定义的函数实现传值 methods:{
  //事件名(值){} father(valuue){ this.father=this.value } }

猜你喜欢

转载自www.cnblogs.com/cola1orz/p/11252300.html