1.父组件使用子组件的方法
// 1.首先在父组件中使用调用的子组件 并使用id类名,为之后准确查找,注意不是在子组件中定义类型
<header id='myHeader' title="{{title}}"></header>
// 2.在父组件的js文件中使用子组件的方法
run2() {
var header = this.selectComponent('#myHeader')
header.run()
},
2.子组件使用父组件的方法
// 1.首先在子组件中发布事件,userChild是发布的方法,value 是发布的同时携带的参数
run() {
var value = 123
this.triggerEvent('userChild',value)
}
// 2.在父组件中接收对应子组件发布的事件,bind后面执行的方法是子组件发布的方法,run3是对应父组件自身的方法
<footer bind:userChild='run3'></footer>
//js文件中
run3(val) {
console.log('because I want free',val)
},