文章目录
通信方法
组件通信
properties
父组件向子组件通信,与 Vue 的 props 作用相同。
父组件向子组件传数据:
<my-component list="{
{list}}"></my-component>
子组件接收数据:
Component({
properties:{
list:{
type: Array,
value: []
}
},
attached(){
console.log(this.list)
}
})
triggerEvent
子组件向父组件通信,与 Vue 的 $emit 作用相同
子组件触发自定义事件:
Component({
attached(){
this.triggerEvent('customEvent',{
id: 10 })
}
})
父组件接收自定义事件:
<my-component list="{
{list}}" bind:customEvent="customEvent"></my-component>
Page({
customEvent(e)</

本文详细介绍了微信小程序中组件通信、页面通信以及全局通信的各种方法。包括使用properties实现父组件向子组件传递数据,利用triggerEvent实现子组件向父组件的反馈,通过selectComponent选择并操作组件实例,利用getCurrentPages获取页面栈进行跨页面通信,wx.navigateTo进行页面跳转并传递数据,以及如何使用globalData和storage进行全局数据管理和存储。这些通信方式对于微信小程序的开发至关重要。
最低0.47元/天 解锁文章
1408

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



