官网文档形容父组件不能调用子组件的办法 其实是能够的记录下以便日后应用
//子组件.axml
<text>我只是一个子组件</text>
//子组件.js
methods:{
childMethod(){
console.log("调用到了子组件的办法")
}
}
//父组件.json
{
child-compoent: '../componets/子组件门路'
}
//父组件.axml
<child-compoent ref="childMethods" />
//用ref来指向子组件
//父组件.js
{
childMethods(ref){//注册子组件实例来调用子组件办法
this.childCompoentMethod = ref
},
callChildCompoentMethods(){
this.childCompoentMethod.childMethod()
}
}
这样就能够调用到子组件的办法啦
发表回复