antoniputra antoniputra - 3 months ago 103
Javascript Question

Using lodash in all of vue component template

Can I using lodash

_
in all of my vue component?

for example:

I have components organized like below:

App.vue
>
Parent.vue
>
Child.vue


I would like to all of my component can access
_
lodash without defined in every component vm
data


===

I am also trying using Mixins. it works. but the result not expected like this
_().isEmpty()
instead of
_.isEmpty()

Answer

You could import the lodash into each component:

<script>
  import _ from 'lodash'

  export default {
    methods: {
      test (value) {
        return _.isEmpty(value)
      }
    }
  }
</script>