1.0.8 • Published 5 years ago

vue-event-x v1.0.8

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

基于 Vue 的事件管理

使用方法

import Event, { EventMixin } from "vue-event-x";

Vue.use(Event);

new Vue({ mixins: [EventMixin(eventName | { options })] });

导入 Event 之后使用 use 进行安装。

当你的组件存在习销毁和重建的时候,你需要混入 EventMixin(建议无脑混入)。

EventMixin 混入接受一个字符串,或者是 options 配置对象,会自动创建事件总线。

options

配置参数

属性类型描述
nameString事件总线名称
replaceBoolean如果名称重复,是否进行覆盖,覆盖会删掉之前重名的事件总线,然后创建新的总线

\$EventX,全局对象是 event-x 的通用 api。

this.$EventX = {
    createNewBus,
    destroy,
    error,
    isDestroy,
    state
};
方法参数描述
createNewBus{name: 'eventName'}创建新的消息总线,需要传入消息总线的名称。
destroy{name: 'eventName'}销毁消息总线,需要传入消息总线的名称。
errorfn全局错误处理。
isDestroyedname查询消息总线的是否被销毁。
statename|null查询消息总线的状态。

事件总线的 api

this.$demoEvent = {
    on,
    off,
    emit,
    error,
    offError,
    destroy,
    state
};
方法参数描述
ontype,fn,option|{type,fn,option}|{type: fn}监听事件
offtype, fn, isAll=false卸载监听事件处理器,isAll=true 的时候会同时写在所有的错误处理
emittype,...args事件触发
errorfn|type,fn错误处理,只传 fn 则全局错误处理,传入 type 可以对单个事件进行错误处理。fn 的参数为:error, type, ...data
offErrorfn|type,fn卸载错误处理器,传入 type 卸载指定类型的错误处理器,未传入 type 咋卸载对应的全局错误处理器
destroy销毁当前时间总线
state当前总线状态

Future

异步事件

错误实现

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago