{"id":13536101,"url":"https://github.com/yangmingshan/vue-bus","last_synced_at":"2025-04-12T19:52:26.515Z","repository":{"id":39737677,"uuid":"73187284","full_name":"yangmingshan/vue-bus","owner":"yangmingshan","description":"A event bus for Vue.js","archived":false,"fork":false,"pushed_at":"2023-03-04T03:27:03.000Z","size":802,"stargazers_count":311,"open_issues_count":4,"forks_count":32,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-12T19:52:19.624Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/yangmingshan.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-11-08T13:13:30.000Z","updated_at":"2025-02-09T09:17:49.000Z","dependencies_parsed_at":"2024-01-18T04:08:01.653Z","dependency_job_id":"2502b40c-154d-4d7a-a76d-702530e2a660","html_url":"https://github.com/yangmingshan/vue-bus","commit_stats":{"total_commits":28,"total_committers":6,"mean_commits":4.666666666666667,"dds":0.4285714285714286,"last_synced_commit":"d51aea3ef1c2b85a14a220f909a292e4b5b3f118"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangmingshan%2Fvue-bus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangmingshan%2Fvue-bus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangmingshan%2Fvue-bus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangmingshan%2Fvue-bus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yangmingshan","download_url":"https://codeload.github.com/yangmingshan/vue-bus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625506,"owners_count":21135513,"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":[],"created_at":"2024-08-01T09:00:34.679Z","updated_at":"2025-04-12T19:52:26.489Z","avatar_url":"https://github.com/yangmingshan.png","language":"JavaScript","funding_links":[],"categories":["实用库","JavaScript"],"sub_categories":[],"readme":"# vue-bus [![Build Status](https://img.shields.io/circleci/project/yangmingshan/vue-bus.svg)](https://circleci.com/gh/yangmingshan/vue-bus) [![Coverage Status](https://img.shields.io/codecov/c/github/yangmingshan/vue-bus.svg)](https://codecov.io/gh/yangmingshan/vue-bus) [![Downloads](https://img.shields.io/npm/dt/vue-bus.svg)](https://www.npmjs.com/package/vue-bus) [![Version](https://img.shields.io/npm/v/vue-bus.svg)](https://www.npmjs.com/package/vue-bus) [![License](https://img.shields.io/npm/l/vue-bus.svg)](https://www.npmjs.com/package/vue-bus)\n\nA event bus for Vue.js, support both Vue 1.0 and 2.0. See Vue [documentation](https://vuejs.org/v2/guide/migration.html#Events) for more detail.\n\n## Installation\nYou can install it via [yarn](https://yarnpkg.com) or [npm](https://npmjs.com).\n```\n$ yarn add vue-bus\n$ npm install vue-bus --save\n```\nAnd it's available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-bus/dist/vue-bus.js) or [unpkg](https://unpkg.com/vue-bus/dist/vue-bus.js).\n```html\n\u003c!-- development version --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/vue-bus/dist/vue-bus.js\"\u003e\u003c/script\u003e\n\n\u003c!-- production version --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/vue-bus/dist/vue-bus.min.js\"\u003e\u003c/script\u003e\n```\nWhen used with a module system, you must explicitly install the bus via Vue.use():\n```js\nimport Vue from 'vue';\nimport VueBus from 'vue-bus';\n\nVue.use(VueBus);\n```\nYou don't need to do this when using global script tags.\n\n## Usage\n#### Listen and clean\n```js\n// ...\ncreated() {\n  this.$bus.on('add-todo', this.addTodo);\n  this.$bus.once('once', () =\u003e console.log('This listener will only fire once'));\n},\nbeforeDestroy() {\n  this.$bus.off('add-todo', this.addTodo);\n},\nmethods: {\n  addTodo(newTodo) {\n    this.todos.push(newTodo);\n  }\n}\n```\n#### Trigger\n```js\n// ...\nmethods: {\n  addTodo() {\n    this.$bus.emit('add-todo', { text: this.newTodoText });\n    this.$bus.emit('once');\n    this.newTodoText = '';\n  }\n}\n```\n#### Another way to use vue-bus\n```js\n// xxx.js\nimport Vue from 'vue';\n\nVue.bus.emit('someEvent');\n```\n*Note: `on` `once` `off` `emit` are aliases for `$on` `$once` `$off` `$emit`. See the [API](https://vuejs.org/v2/api/#Instance-Methods-Events) for more detail.*\n\n## License\n[MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyangmingshan%2Fvue-bus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyangmingshan%2Fvue-bus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyangmingshan%2Fvue-bus/lists"}