当前位置: 首页 > Web前端 > HTML5

支付宝小程序父组件调用子组件的方法

时间:2023-04-05 17:20:32 HTML5

官方文档描述是父组件不能调用子组件的方法。其实可以记录下来,以备后用。//Subcomponent.axml我只是一个子组件//Childcomponent.jsmethods:{childMethod(){console.log("调用到子组件的方法")}}//Parentcomponent.json{child-component:'../components/子组件路径'}//parentcomponent.axml//使用ref指向子组件//父组件.js{childMethods(ref){//注册子组件实例调用子组件方法this.childCompoentMethod=ref},callChildComponentMethods(){this.childComponentMethod.childMethod()}}这样就可以调用子组件的方法了子组件