父组件主动获取子组件的数据和方法
1.调用子组件的时候 定义一个ref

  <headerchild ref="headerChild"></headerchild>

  在父组件里面通过

  this.$refs.headerChild.属性
  this.$refs.headerChild.方法

2.子组件主动获取父组件的数据和方法   element-ui中 不行
  在子组件里面通过

  this.$parent.属性
  this.$parent.方法

3. 子组件获取父组件(无层级限制)

父组件:

provide() {
    return {
      template: this
    }
  }
 
子组件
inject: ['template']
 
子组件通过this.template.属性    this.template.方法

相关文章:

  • 2022-12-23
  • 2021-04-30
  • 2021-06-27
  • 2021-05-31
  • 2021-07-21
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-05-19
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案