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

官方文档描述父组件不能调用子组件的方法 其实是可以的记录下以便日后使用

//子组件.axml
我只是一个子组件



//子组件.js
methods:{
    childMethod(){
        console.log("调用到了子组件的方法")
    }
}

//父组件.json

{
    child-compoent: '../componets/子组件路径'
}


//父组件.axml

//用ref来指向子组件


//父组件.js
{
    childMethods(ref){//注册子组件实例来调用子组件方法
        this.childCompoentMethod = ref
    },
    callChildCompoentMethods(){
        this.childCompoentMethod.childMethod()
    }
}

这样就可以调用到子组件的方法啦

你可能感兴趣的:(javascript,html5,html,支付宝小程序)