vue-lodash

A small wrapper for integrating lodash into VueJs
853,868 105
Install
npm install vue-lodash
Latest Version:2.1.2
Vue:2
License:MIT
Last Updated:Jan 8, 2023
Links: GitHub  ·  npm
Maintainer: ewocker

vue-lodash

NPM Known Vulnerabilities GitHub license

A small wrapper for integrating lodash to Vuejs (Inspired by vue-axios plugin)

Install

npm install --save vue-lodash lodash

Usage

import Vue from 'vue'
import VueLodash from 'vue-lodash'
import lodash from 'lodash'

// name is optional
Vue.use(VueLodash, { name: 'custom' , lodash: lodash })

new Vue({
  el: '#app',
  methods: {
    test() {
      console.log(this.lodash.random(20))
      console.log(this._.random(20))
      console.log(this.custom.random(20))
    },
  }
})
console.log(Vue.lodash.random(20))
console.log(Vue._.random(20))
console.log(Vue.custom.random(20))

Typescript

Using custom name with typescript is currently unsupported without casting.

import Vue from 'vue'
import VueLodash from 'vue-lodash'
import lodash from 'lodash'

Vue.use(VueLodash, { name: 'custom', lodash: { map, random } })

new Vue({
  el: '#app',
  methods: {
    testLodash() {
      console.log(this.lodash.random(20))
      console.log(this._.random(20))
      console.log((this as any).custom.random(20))
    },
  }
})
console.log(Vue.lodash.random(20))
console.log(Vue._.random(20))
console.log((Vue as any).custom.random(20))

Tree shaking with lodash

Only import the packages you need, note that lodash tree shaking has to do import with path to module.

import Vue from 'vue'
import VueLodash from 'vue-lodash'
import random from 'lodash/random'
import map from 'lodash/map'

Vue.use(VueLodash, { name: 'custom', lodash: { map, random } })

Related Packages

vue-axios

A small wrapper for integrating axios to Vuejs

5,218,200 1,996
vue-momentjs

A tiny Moment.js wrapper for Vue.

71,108 21
vue-cli-plugin-lodash

vue-cli plugin for lodash

4,260 4
nuxt-lodash

Lodash for Nuxt

1,032,866 112
vue-electron

The vue plugin that attaches electron APIs to the Vue object, making them access...

161,317 294

Version History

Version Released License
2.1.2 MIT
2.1.1 MIT
2.1.0 MIT
2.0.2 AFL-2.0
2.0.1 AFL-2.0