Blogger Information
Blog 67
fans 0
comment 2
visits 72019
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue3父子组件之间的访问方式
搁浅
Original
2005 people have browsed it

子组件调用父组件的方法:$parent 或 $root

父组件调用子组件的方法:$children 或 $refs

子访问父

  1. one() {
  2. console.log('这是子组件中的one()')
  3. this.$parent.changen(); //调用父的方法
  4. console.log(this.$parent.count); //调用父的属性
  5. console.log(this.$parent.$parent.msg); //调用父的父成员
  6. this.$root.appmet(); //调用根的成员
  7. },

父访问子

  1. //给子组件设置别名
  2. <my-conn ref="aaa"></my-conn>
  3. <my-conn ref="bbb"></my-conn>
  4. two() {
  5. console.log('这是父组件中的two方法')
  6. this.$refs.aaa.changeone(); //调用别名为aaa的子组件方法
  7. this.$refs.bbb.changeone(); //调用别名为bbb的子组件方法
  8. console.log(this.$refs.aaa.num) //访问子组件成员
  9. console.log(this.$refs.bbb.num) //访问子组件成员
  10. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post