{"id":13682615,"url":"https://github.com/sandeepk01/vue-event-handler","last_synced_at":"2025-04-30T09:33:23.618Z","repository":{"id":57395830,"uuid":"79716292","full_name":"sandeepk01/vue-event-handler","owner":"sandeepk01","description":"Event handling plugin for VueJS","archived":false,"fork":false,"pushed_at":"2019-06-07T04:05:35.000Z","size":9,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-04T04:18:14.796Z","etag":null,"topics":["event-handlers","event-listener","eventbus","vue","vue1-events","vue2-events"],"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/sandeepk01.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-01-22T12:25:20.000Z","updated_at":"2023-04-08T13:51:58.000Z","dependencies_parsed_at":"2022-09-03T06:43:31.421Z","dependency_job_id":null,"html_url":"https://github.com/sandeepk01/vue-event-handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepk01%2Fvue-event-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepk01%2Fvue-event-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepk01%2Fvue-event-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeepk01%2Fvue-event-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandeepk01","download_url":"https://codeload.github.com/sandeepk01/vue-event-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224175772,"owners_count":17268389,"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":["event-handlers","event-listener","eventbus","vue","vue1-events","vue2-events"],"created_at":"2024-08-02T13:01:49.723Z","updated_at":"2024-11-12T02:31:11.182Z","avatar_url":"https://github.com/sandeepk01.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Awesome Vue.js [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)","公用事业","Components \u0026 Libraries","Utilities","Utilities [🔝](#readme)"],"sub_categories":["Libraries \u0026 Plugins","自定义事件","Utilities","Custom Events"],"readme":"A [Vue.js](http://vuejs.org) plugin that provides a global event bus and a couple helper methods.\n\nWorks with both `Vue 1.0` \u0026 `Vue 2.0`.\n\n## Installation\n\n##### 1.) Install package via NPM\n```\nnpm install vue-event-handler\n```\n\n##### 2.) Install plugin within project.\n```\nimport Vue from 'vue';\nimport VueEvents from 'vue-event-handler';\n\nVue.use(VueEvents)\n```\n\nor\n\n```\nwindow.Vue = require('vue');\nrequire('vue-event-handler');\n```\n\n## Usage\n\n#### The `$events` prototype object.\nThis plugin extends `Vue.prototype` to include a new `$events` object. The `$events` object is a simple Vue model which\nincludes couple aliases for the `vm.$emit` \u0026 `vm.$on` methods. An event when registered becomes globally available and thus\ncan be handy while passing data between components.\n\n#### Registering an event\nThere are a couple of methods that can be used to register an event and attach a handler method.\nOption 1 \u0026 2 are functionally identical, and so is Option 3 \u0026 4.\n```\nnew Vue({\n\n\tmounted () {\n\t\t// Option 1 - Keeps listening until destroyed\n        this.$events.listen('eventName', eventData =\u003e console.log(eventData));\n        \n        // Option 2 - Keeps listening until destroyed\n        this.$events.on('eventName', eventData =\u003e console.log(eventData));\n\t\t\n\t\t// Option 3 - Listens only once and then stops responding to the trigger, but is not destroyed\n        this.$events.listenOnce('eventName', eventData =\u003e console.log(eventData));\n\t\t\n\t\t// Option 4 - Listens only once and then stops responding to the trigger, but is not destroyed\n        this.$events.once('eventName', eventData =\u003e console.log(eventData));\n\t}\n})\n```\n\n#### Firing an event\nThere are 2 methods that fire events. Both options are functionally identical.\n\n```\nnew Vue({\n\n    data() {\n        return {\n            eventData: {\n                foo: 'baz'\n            }\n        }\n    },\n    \n    mounted() {\n        // Option 1\n        this.$events.fire('eventName', this.eventData);\n        \n        // Option 2\n        this.$events.emit('eventName', this.eventData);\n    }\n    \n})\n```\n\n#### Destroying an event\nThere is a method to de-register/destroy an event listener. These method becomes handy whenever the scope of a Vue component\nis lost and the event was being used locally.\n\n```\nnew Vue({\n\n\tbeforeDestroy () {\n\t\t// Option 1 - Destroys an event\n\t\tthis.$events.off('eventName');\n\t\t\n\t\t// Option 2 - Destroys an event\n\t\tthis.$events.unlisten('eventName');\n\t\t\n\t\t// Option 3 - Destroys all event listeners globally\n\t\tthis.$events.removeAll();\n\t}\n})\n```\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandeepk01%2Fvue-event-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandeepk01%2Fvue-event-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandeepk01%2Fvue-event-handler/lists"}