cklmercer / vue-events

Simple event handling for Vue.js
MIT License
234 stars 27 forks source link

Error: cannot redefine property: $events #15

Open acacha opened 6 years ago

acacha commented 6 years ago

If I use this package in 2 different libraries and then use this 2 librares in another one then thw following problem occurs:

index.js:104 Uncaught TypeError: Cannot redefine property: $events
    at Function.defineProperty (<anonymous>)
    at plugin (index.js:104)
    at Function.Vue.use (vue.common.js:4618)
    at Object.disposed (index.js:148)
    at __webpack_require__ (bootstrap 7ecffedbdf2f7047c51d:19)
    at Object.disposed (forge-bootstrap.js:1)
    at __webpack_require__ (bootstrap 7ecffedbdf2f7047c51d:19)
    at Object.<anonymous> (app.js:18)
    at __webpack_require__ (bootstrap 7ecffedbdf2f7047c51d:19)
    at Object.<anonymous> (app.js:25575)

Any clue how can I solve this problem?

acacha commented 6 years ago

I can avoid this problem using:

// Extend `Vue.prototype` to include our global event bus.
  if (! Vue.prototype.hasOwnProperty('$events')) {
    Object.defineProperty(Vue.prototype, '$events', {
      get: function get() {
        return events;
      }
    });
  }

When defining $events property. Do you want I create a PR? But reading the code ti seems to me that this is a Bug related with:

  if (plugin.installed) return

Maybe only works with vue 1?

cklmercer commented 6 years ago

Feel free to PR the code change from above. I'll take a look and make sure everything is square before publishing a new version.