微信小程序开发中组件之间的数据如何共享

第一步:新建my-component.js文件
导出 module.exports = Behavior({
data:{
title:"张三"
},
methods:{
fn(){
wx.showToast({
title:"我来了,你在哪?"
})
}
}

)
需要共享的数据下在data里面,需要共享的方法写在methods里面
第二部:引入使用共享的数据和方法
const myBehavior = require("../../my-component")
引入后还需在Component中设置
Component({
behaviors:[myBehavior] //可以写多个哦
})
这样就可以使用共享的数据和方法了