hy-event-store icon indicating copy to clipboard operation
hy-event-store copied to clipboard

缺少全局事件,期待老师更新

Open zhixu369 opened this issue 2 years ago • 2 comments

希望能在wxml页面中通过bindtap=“事件名称”的方式绑定全局事件,比如全局跳转。

zhixu369 avatar Apr 12 '22 04:04 zhixu369

具体描述一下什么样的全局事件绑定呢?

coderwhy avatar Apr 21 '23 02:04 coderwhy

比如,我定义了如下的全局状态和方法 const eventStore = new HYEventStore({  state: {    name: "why",  },   actions: {  //全局跳转方法  goUrl(path) {    wx.navigateTo({    url:path   })  }  } })

然后我可以这样使用,在.wxml中 <view> <text>{{name}}</text> <button bind:tap="goUrl" data-path="/pages/good/index">跳转</button> </view>

这样,就不用总是在页面的js中定义data和method了,相当于全局的响应式data和全局的方法,用起来特别方便

zhixu369 avatar Apr 22 '23 02:04 zhixu369