vue-bus.common.js 854 B

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