{"id":13701286,"url":"https://github.com/pagekit/vue-event-manager","last_synced_at":"2025-05-04T21:30:41.699Z","repository":{"id":20325807,"uuid":"89473008","full_name":"pagekit/vue-event-manager","owner":"pagekit","description":"The event manager for Vue.js","archived":true,"fork":false,"pushed_at":"2022-12-10T17:04:20.000Z","size":3180,"stargazers_count":82,"open_issues_count":19,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-18T03:05:25.110Z","etag":null,"topics":["events","javascript","vue"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pagekit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-26T11:25:13.000Z","updated_at":"2023-12-01T10:06:39.000Z","dependencies_parsed_at":"2022-07-25T12:33:16.454Z","dependency_job_id":null,"html_url":"https://github.com/pagekit/vue-event-manager","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagekit%2Fvue-event-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagekit%2Fvue-event-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagekit%2Fvue-event-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagekit%2Fvue-event-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pagekit","download_url":"https://codeload.github.com/pagekit/vue-event-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252403670,"owners_count":21742407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["events","javascript","vue"],"created_at":"2024-08-02T20:01:26.895Z","updated_at":"2025-05-04T21:30:40.839Z","avatar_url":"https://github.com/pagekit.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","公用事业","Components \u0026 Libraries","Utilities","Utilities [🔝](#readme)"],"sub_categories":["自定义事件","Utilities","Custom Events"],"readme":"# vue-event-manager [![Build](https://circleci.com/gh/pagekit/vue-event-manager.svg?style=shield)](https://circleci.com/gh/pagekit/vue-event-manager) [![Downloads](https://img.shields.io/npm/dm/vue-event-manager.svg)](https://www.npmjs.com/package/vue-event-manager) [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/vue-event-manager/badge?style=rounded)](https://www.jsdelivr.com/package/npm/vue-event-manager) [![Version](https://img.shields.io/npm/v/vue-event-manager.svg)](https://www.npmjs.com/package/vue-event-manager) [![License](https://img.shields.io/npm/l/vue-event-manager.svg)](https://www.npmjs.com/package/vue-event-manager)\n\nThe plugin for [Vue.js](http://vuejs.org) provides a declarative way to bind events to a global event manager. It uses the Vue lifecycle to automatically bind and unbind all events.\n\n## Features\n\n- Supports event priorities and [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) based asynchronous events\n- Supports latest Firefox, Chrome, Safari, Opera and IE9+\n- Supports Vue 2.0\n- Compact size 3KB (1,5KB gzipped)\n\n## Installation\nYou can install it via [yarn](https://yarnpkg.com) or [NPM](https://npmjs.org).\n```\n$ yarn add vue-event-manager\n$ npm install vue-event-manager\n```\n\n### CDN\nAvailable on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-event-manager@2.1.3) or [unpkg](https://unpkg.com/vue-event-manager@2.1.3).\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/vue-event-manager@2.1.3\"\u003e\u003c/script\u003e\n```\n\n## Example\nTry the example on [jsfiddle](https://jsfiddle.net/gh/get/library/pure/pagekit/vue-event-manager/tree/master/examples/demo/).\n```js\nnew Vue({\n\n  created() {\n\n    // trigger event\n    this.$trigger('someEvent', {foo: 'bar'});\n\n  },\n\n  events: {\n\n    // event handler (priority 0)\n    someEvent(event, param) { ... },\n\n    // event handler (priority 10)\n    earlyEvent: {\n\n        // handler callback\n        handler(event, param) { ... },\n\n        // a higher priority, means earlier execution\n        priority: 10\n\n    },\n\n    // event handler (priority -10)\n    lateEvent: {\n\n        // handler callback\n        handler(event, param) { ... },\n\n        // a lower priority, means late execution\n        priority: -10\n\n    }\n\n  }\n\n});\n```\n\nLets see how **easy** you can **watch global events** like reactive properties! (Like in this [example](https://vuejs.org/v2/examples/commits.html)).\nLet's assume you have a logout button in any component template and want it to be handled *somewhere else* without these nasty `$on(...)` and `$off(...)` lines in the created and destroy hooks.\n\n```html\n\u003c!-- logoutButton.vue --\u003e\n\u003cbutton @click=\"$trigger('logout:the-user')\"\u003eLogout\u003c/button\u003e\n```\n\n```js\n// userManager.vue\nexport default {\n\n  name: 'any-other-component',\n\n  events: {\n    // the event name string binds the method name string\n    'logout:the-user': 'logout'\n  },\n\n  methods: {\n    // this method will be called everytime the event occurs\n    logout (event, param) {\n      this.$http.post('/logout')\n    }\n  }\n\n}\n```\n\n## Changelog\n\nDetails changes for each release are documented in the [release notes](https://github.com/pagekit/vue-event-manager/releases).\n\n## Contribution\n\nIf you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/pagekit/vue-event-manager/issues) or a [pull request](https://github.com/pagekit/vue-event-manager/pulls).\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpagekit%2Fvue-event-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpagekit%2Fvue-event-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpagekit%2Fvue-event-manager/lists"}