vue-bus.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. * vue-bus v1.2.1
  3. * https://github.com/yangmingshan/vue-bus
  4. * @license MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. (global = global || self, global.VueBus = factory());
  10. }(this, function () { 'use strict';
  11. function VueBus(Vue) {
  12. var bus = new Vue();
  13. Object.defineProperties(bus, {
  14. on: {
  15. get: function get() {
  16. return this.$on.bind(this)
  17. }
  18. },
  19. once: {
  20. get: function get() {
  21. return this.$once.bind(this)
  22. }
  23. },
  24. off: {
  25. get: function get() {
  26. return this.$off.bind(this)
  27. }
  28. },
  29. emit: {
  30. get: function get() {
  31. return this.$emit.bind(this)
  32. }
  33. }
  34. });
  35. Object.defineProperty(Vue, 'bus', {
  36. get: function get() {
  37. return bus
  38. }
  39. });
  40. Object.defineProperty(Vue.prototype, '$bus', {
  41. get: function get() {
  42. return bus
  43. }
  44. });
  45. }
  46. if (typeof window !== 'undefined' && window.Vue) {
  47. window.Vue.use(VueBus);
  48. }
  49. return VueBus;
  50. }));