Using global lodash with quasar v15 (Solved)

  • Hi guys, newbie here i need some help on how to import lodash and use it globally?

    I followed the instructions on how to install some package as plugins but I think I’m missing something.

    here is my code:

    // here I import the lodash and use it on Vue
    import lodash from 'lodash'
    // leave the export, even if you don't use it
    export default ({ app, router, Vue }) => {

    but then when i tested out some examples of lodash( like _.chunk(['a', 'b', 'c', 'd'], 2)) to my VUE file ,it says, …error ‘_’ is not defined to my cli

    it fails me… please help me thank you!

  • Admin

    lodash is not a vue package, so it makes no sense to Vue.use(lodash).

    Pick one of these two scenarios:

    1. “I want it globally available in vue files”
    import lodash from 'lodash'
    export default ({ Vue }) => {
      Vue.prototype.$_ = lodash // then use as this.$_
    1. "I want to globally use it, but not through Vue"
      Simply import it in any file (js, vue) and then use the reference to it.

  • Hi @rstoenescu thank you! i picked the first scenario 🙂