自定义方法中发送命令
const app = getApp()
Component({options: {styleIsolation: 'isolated'},data: {},properties: {},attached() {this.init()},methods: {init() {console.log('父组件执行子组件')},clickBtn() {this.triggerEvent('changeRoute', '发送数据到父组件', {})},}
})
父组件接收 changeRoute 方法
<child id="child" bindchangeRoute="changeRoute" />// 接收数据
changeRoute(e) {console.log(e.detail) // 发送数据到父组件
}
父组件执行子组件命令(注意 子组件的 id)
this.selectComponent("#child").init() // 父组件执行子组件