EventChannel.emit(string eventName, any args) //像子组件像父组件传值
EventChannel.on(string eventName, EventCallback fn) //持续监听事件
EventChannel.off(string eventName, EventCallback fn) //取消监听监听事件
EventChannel.once(string eventName, EventCallback fn) //触发后失效 只监听一次
eventChannel 是页面跳转success()回调里的一个方法
// componText
wx.navigateTo({
url: '../logs/logs',
success:function(res){
res.eventChannel.emit('toLogs',{ data: '我是来自 componText 页面的数据' })
}
})
logs日志页面
onLoad: function () {
const eventCannel = this.getOpenerEventChannel()
eventCannel.on("toLogs",res=>{
console.log(res) //{ data: '我是来自 componText 页面的数据' }
})
}