Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • react+ts父组件调用子组件方法

react+ts父组件调用子组件方法

父组件

child: any = {}  //主要加这个
onRef = (ref: any) => {
    this.child = ref
}
showEditAdminModal = (admin?: IAdmin) => {
    // 调用子组件
    this.child.getEnableProvinces()
 }


 <ChangeArea
          onRef={this.onRef}
          visible={this.state.showEditAdminModal}
          cancel={this.hideEditAdminModal}
      />

子组件

interface IProps {
    visible: boolean
    cancel: (refresh?: boolean) => void
    onRef: (ref: any) => void
}

componentDidMount() {
    this.props.onRef(this)
}

getEnableProvinces() {

}
Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人