[Vuejs]-Vue error with Rangy library: "โ€ฆ" is not a function (but only inside hooks)

1๐Ÿ‘

โœ…

I had to use rangy.init() which initializes Rangy if it has not already been initialized:
https://github.com/timdown/rangy/wiki/Rangy-Object#rangyinit

๐Ÿ‘คPida

2๐Ÿ‘

I would recommend making a Vue plugin out of this to make it easier:

// plugins/vue-rangy.js

import rangy from 'rangy'

const VueRangy = {
  install (Vue, options) {
      if (options.hasOwnProperty('init') && options.init) {
        rangy.init()
      }

      Vue.prototype.$rangy = rangy
  }
}

export default VueRangy

Then use it like any other plugin:

import VueRangy from 'plugins/vue-rangy'

Vue.use(VueRangy, {
  init: true
})

Then just use this.$rangy in your components.

๐Ÿ‘คOhgodwhy

Leave a comment