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 页面的数据' }
})
}
该博客围绕微信小程序展开,介绍了EventChannel的相关方法,如用于子组件向父组件传值的emit方法、持续监听事件的on方法、取消监听的off方法以及触发后失效的once方法,还提及eventChannel是页面跳转success回调里的方法和logs日志页面。
593

被折叠的 条评论
为什么被折叠?



