coderwhy / hy-event-store

An event-based global state management tool for vue, react, mini-program, ect.
393 stars 45 forks source link

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

Open zhixu369 opened 2 years ago

zhixu369 commented 2 years ago

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

coderwhy commented 1 year ago

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

zhixu369 commented 1 year ago

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

然后我可以这样使用,在.wxml中 `

{{name}}
<button bind:tap="goUrl" data-path="/pages/good/index">跳转</button>

`

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