0
点赞
收藏
分享

微信扫一扫

原生微信小程序父组件调用子组件中的方法

流沙雨帘 2022-02-22 阅读 79

假设子组件中写有方法getData()

// 返回数据
getData() {
    let flag = this.onStartValidate();
    if (!flag) return false
    let { form } = this.data;
    return form;
},

在父组件中的json文件中注册子组件,

在父组件中的wxml文件中引入子组件,并定义id

<sh-batch id="shBatch" form="{{ sendForm }}"></sh-batch>

最后在负组件中的js文件中调用selectComponent()方法就可以直接调用子组件中的方法

let form = this.selectComponent("#shBatch").getData();
举报

相关推荐

0 条评论