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

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

相关文章:

  • 2021-11-18
  • 2021-11-20
  • 2022-12-23
  • 2021-03-31
  • 2021-05-30
  • 2021-09-05
  • 2021-07-31
  • 2021-06-16
猜你喜欢
  • 2021-09-01
  • 2022-01-07
  • 2021-12-03
  • 2021-12-09
  • 2021-11-06
  • 2022-01-02
  • 2021-06-12
相关资源
相似解决方案